diff --git a/scripts/core/helpers/CrudManager.tsx b/scripts/core/helpers/CrudManager.tsx index d0b2eec74b..11a0adbcd3 100644 --- a/scripts/core/helpers/CrudManager.tsx +++ b/scripts/core/helpers/CrudManager.tsx @@ -121,21 +121,22 @@ export function generatePatchIArticle(a: IArticle, b: IArticle) { return patch; } -const cache = {}; +const _cache = {}; -function findOne(endpoint: string, id: string): Promise { +function findOne(endpoint: string, id: string, cache: boolean = true): Promise { const key = `${endpoint}:${id}`; - if (cache[key] == null) { - cache[key] = httpRequestJsonLocal({ + if (_cache[key] == null) { + _cache[key] = httpRequestJsonLocal({ method: 'GET', path: '/' + endpoint + '/' + id, + cache: cache === false ? 'reload' : 'default', }).finally(() => { - delete cache[key]; + delete _cache[key]; }); } - return cache[key]; + return _cache[key]; } export function fetchChangedResources( diff --git a/scripts/core/helpers/network.tsx b/scripts/core/helpers/network.tsx index dcec28aaae..1b4249715c 100644 --- a/scripts/core/helpers/network.tsx +++ b/scripts/core/helpers/network.tsx @@ -7,6 +7,7 @@ interface IHttpRequestOptions { payload?: {}; headers?: {[key: string]: any}; urlParams?: {[key: string]: any}; + cache?: 'default' | 'no-store' | 'reload' | 'no-cache' | 'force-cache' | 'only-if-cached'; abortSignal?: AbortSignal; } diff --git a/scripts/core/superdesk-api.d.ts b/scripts/core/superdesk-api.d.ts index 733e0c62d9..891368be9b 100644 --- a/scripts/core/superdesk-api.d.ts +++ b/scripts/core/superdesk-api.d.ts @@ -2553,7 +2553,7 @@ declare module 'superdesk-api' { } export interface IDataApi { - findOne(endpoint: string, id: string): Promise; + findOne(endpoint: string, id: string, cache?: boolean): Promise; create(endpoint: string, item: Partial, urlParams?: Dictionary): Promise; query( endpoint: string,