フィルターのクリア

how to get uncached data from webread

10 ビュー (過去 30 日間)
Kamal
Kamal 2024 年 5 月 2 日
回答済み: Chetan 2024 年 5 月 2 日
I am using the webread to get the data from the following api:
The data has been updated via the backend and it seems like i am getting a stale data

採用された回答

Chetan
Chetan 2024 年 5 月 2 日
Hi @Ketan,
I understand that you're using MATLAB's `webread` function to fetch updated data from an API but are receiving stale data despite backend updates.
As a workaround you can try the following steps:
1. Cache Issue: Append a unique query parameter to bypass potential caching, using the current timestamp as a cache buster.
cacheBuster = posixtime(datetime('now'));
url = sprintf('https://us-central1-techspardha-87928.cloudfunctions.net/api2/events/description?eventCategory=Programming&eventName=Productathon&cb=%d', cacheBuster);
data = webread(url)
data = struct with fields:
data: [1x1 struct] success: 1
2. Headers Adjustment: Use `weboptions` to set `Cache-Control: no-cache` in the request header.
options = weboptions('HeaderFields', {'Cache-Control','no-cache'});
url = 'https://us-central1-techspardha-87928.cloudfunctions.net/api2/events/description?eventCategory=Programming&eventName=Productathon';
data = webread(url, options)
data = struct with fields:
data: [1x1 struct] success: 1
3. Ensure the server's caching policies are correctly configured to serve the latest data.
Refer to the following MathWorks Documentation for more details:
Thanks
Chetan

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by