-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache project #837
Cache project #837
Conversation
✅ Deploy Preview for madoc-storybook ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
if (Object.keys(slowRequestStore).length > 50) { | ||
// Sort by slowest. | ||
const sorted = Object.values(slowRequestStore).sort((a, b) => b.slowest - a.slowest); | ||
const slowest = sorted.pop(); | ||
if (slowest && slowest.key) { | ||
delete slowRequestStore[slowest.key]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't ideal, but it prevents looping every entry on line 23. There is a finite number route too - so if it is a problem it can be removed completely.
Preview docker image available
|
cache.put(key, result, timeInMs); | ||
cache.put(`@stale/${key}`, result, staleTimeInMs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the source code of memory-cache
. It doesn't copy the result
, so the extra memory to keep a stale copy is only the size of the key. The memory is released when you put the stale copy. It will mean that for infrequent requests we will hold onto stale data for longer. I've set it to 8 hours for now. (The service will also restart the node process if max memory is reached).
This adds 3 features:
The request trace is visible on the System page in the admin.
It can be disabled with the environment variable flag:
DISABLE_SLOW_REQUEST_TRACKING=true