diff --git a/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx index 351e039ca45df..94e42f1b91160 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/ServiceMap/index.tsx @@ -42,6 +42,7 @@ export function ServiceMap({ serviceName }: ServiceMapProps) { const { start, end, environment } = urlParams; if (start && end) { return callApmApi({ + isCachable: false, pathname: '/api/apm/service-map', params: { query: { diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx index b9f8fd86d067b..43002c79aa2b4 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AgentConfigurationCreateEdit/ServicePage/ServicePage.tsx @@ -36,7 +36,7 @@ export function ServicePage({ newConfig, setNewConfig, onClickNext }: Props) { callApmApi => { return callApmApi({ pathname: '/api/apm/settings/agent-configuration/services', - forceCache: true + isCachable: true }); }, [], diff --git a/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts b/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts index 747144690bb24..ee3d2e81f259f 100644 --- a/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts +++ b/x-pack/legacy/plugins/apm/public/hooks/useDynamicIndexPattern.ts @@ -14,7 +14,7 @@ export function useDynamicIndexPattern( callApmApi => { return callApmApi({ pathname: '/api/apm/index_pattern/dynamic', - forceCache: true, + isCachable: true, params: { query: { processorEvent diff --git a/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts b/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts index 95ebed1fcb2a6..5da237b637abc 100644 --- a/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts +++ b/x-pack/legacy/plugins/apm/public/services/__test__/callApi.test.ts @@ -157,6 +157,46 @@ describe('callApi', () => { expect(http.get).toHaveBeenCalledTimes(1); }); + + it('should not return cached response with `isCachable: false` option', async () => { + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + await callApi(http, { + isCachable: false, + pathname: `/api/kibana`, + query: { start: '2010', end: '2011' } + }); + + expect(http.get).toHaveBeenCalledTimes(3); + }); + + it('should return cached response with `isCachable: true` option', async () => { + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + await callApi(http, { + isCachable: true, + pathname: `/api/kibana`, + query: { end: '2030' } + }); + + expect(http.get).toHaveBeenCalledTimes(1); + }); }); }); }); diff --git a/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts b/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts index 43ecb860a1f1a..d8e3d27f042a9 100644 --- a/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts +++ b/x-pack/legacy/plugins/apm/public/services/rest/callApi.ts @@ -11,7 +11,7 @@ import { HttpSetup, HttpFetchOptions } from 'kibana/public'; export type FetchOptions = Omit & { pathname: string; - forceCache?: boolean; + isCachable?: boolean; method?: string; body?: any; }; @@ -74,8 +74,8 @@ export async function callApi( // only cache items that has a time range with `start` and `end` params, // and where `end` is not a timestamp in the future function isCachable(fetchOptions: FetchOptions) { - if (fetchOptions.forceCache) { - return true; + if (fetchOptions.isCachable !== undefined) { + return fetchOptions.isCachable; } if (