diff --git a/web/libs/datamanager/src/stores/AppStore.js b/web/libs/datamanager/src/stores/AppStore.js index 7971cb9f72af..7cd91a3c06de 100644 --- a/web/libs/datamanager/src/stores/AppStore.js +++ b/web/libs/datamanager/src/stores/AppStore.js @@ -473,7 +473,7 @@ export const AppStore = types }), fetchUsers: flow(function* () { - const list = yield self.apiCall("users"); + const list = yield self.apiCall("users", { __useQueryCache: 60 * 1000 }); self.users.push(...list); }), diff --git a/web/libs/datamanager/src/utils/api-proxy/index.js b/web/libs/datamanager/src/utils/api-proxy/index.js index 28fe36f5859f..e45a28ff7cd2 100644 --- a/web/libs/datamanager/src/utils/api-proxy/index.js +++ b/web/libs/datamanager/src/utils/api-proxy/index.js @@ -155,6 +155,7 @@ export class APIProxy { let responseMeta; const alwaysExpectJSON = options?.alwaysExpectJSON === undefined ? true : options.alwaysExpectJSON; + let shouldUseQueryCache = false; try { const finalParams = { ...(methodSettings.params ?? {}), @@ -162,6 +163,18 @@ export class APIProxy { ...(this.sharedParams ?? {}), }; + if (finalParams.__useQueryCache && methodSettings.queryCache) { + shouldUseQueryCache = true; + + const cachedData = methodSettings.queryCache(finalParams); + + if (cachedData) { + return cachedData; + } + + delete finalParams.__useQueryCache; + } + const { method, url: apiCallURL } = this.createUrl( methodSettings.path, finalParams, @@ -247,7 +260,13 @@ export class APIProxy { : { ok: true }; if (methodSettings.convert instanceof Function) { - return await methodSettings.convert(responseData); + const convertedData = await methodSettings.convert(responseData); + + if (shouldUseQueryCache) { + methodSettings.queryCache(finalParams, convertedData); + } + + return convertedData; } responseResult = responseData; @@ -268,6 +287,10 @@ export class APIProxy { writable: false, }); + if (shouldUseQueryCache) { + methodSettings.queryCache(finalParams, responseResult); + } + return responseResult; }; }