Skip to content

Commit

Permalink
Merge pull request hms-dbmi-cellenics#954 from biomage-org/cache-disable
Browse files Browse the repository at this point in the history
Enabling cache from UI
  • Loading branch information
kafkasl authored Dec 5, 2023
2 parents 085738c + f76ced7 commit 768ded5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
29 changes: 28 additions & 1 deletion src/utils/work/dispatchWorkRequest.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import dayjs from 'dayjs';
import { Environment } from 'utils/deploymentInfo';

import fetchAPI from 'utils/http/fetchAPI';
// Disable unique keys to reallow reuse of work results in development
const DISABLE_UNIQUE_KEYS = [
'GetEmbedding',
];

const getCacheUniquenessKey = (taskName, environment) => {
// Disable cache in development or if localStorage says so
// Do not disable for embeddings requests because download seurat & trajectory depend on that ETag
if (
environment !== Environment.PRODUCTION
&& (localStorage.getItem('disableCache') === 'true' || environment === Environment.DEVELOPMENT)
&& !DISABLE_UNIQUE_KEYS.includes(taskName)
) {
return Math.random();
}

return null;
};

const getWorkerTimeout = (taskName, defaultTimeout) => {
switch (taskName) {
Expand All @@ -21,6 +40,7 @@ const dispatchWorkRequest = async (
body,
timeout,
requestProps,
getState,
) => {
const { name: taskName } = body;

Expand All @@ -32,11 +52,18 @@ const dispatchWorkRequest = async (
// this should be removed if we make each request run in a different worker
const workerTimeoutDate = getWorkerTimeout(taskName, timeout);

const { environment } = getState().networkResources;
const cacheUniquenessKey = getCacheUniquenessKey(taskName, environment);

// eslint-disable-next-line no-param-reassign
requestProps.cacheUniquenessKey = cacheUniquenessKey;

const request = {
experimentId,
timeout: workerTimeoutDate,
body,
...requestProps,
requestProps,

};

const { data: { ETag, signedUrl } } = await fetchAPI(
Expand Down
9 changes: 2 additions & 7 deletions src/utils/work/fetchWork.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Environment, isBrowser } from 'utils/deploymentInfo';
import { isBrowser } from 'utils/deploymentInfo';

import cache from 'utils/cache';
import dispatchWorkRequest from 'utils/work/dispatchWorkRequest';
Expand Down Expand Up @@ -68,11 +68,6 @@ const fetchWork = async (
throw new Error('Disabling network interaction on server');
}

const { environment } = getState().networkResources;
if (environment === Environment.DEVELOPMENT && !localStorage.getItem('disableCache')) {
localStorage.setItem('disableCache', 'true');
}

// 1. Contact the API to get ETag and possible S3 signedURL
const { ETag, signedUrl, request } = await dispatchWorkRequest(
experimentId,
Expand All @@ -82,7 +77,7 @@ const fetchWork = async (
broadcast,
...extras,
},
dispatch,
getState,
);

onETagGenerated(ETag);
Expand Down

0 comments on commit 768ded5

Please sign in to comment.