Comments (9)
I've proposed a bit different thing. Not autorefresh, but background load after request. For examlpe:
- i like to cache data for 60 seconds.
- if next data requested between 60-70 seconts - cache is almost fine, use it and load new data in background.
- if data not requested for a long time - it's completely expired, and loaded in ordinary way, via cache proxy.
No needs to reload each cache slot, only used ones. Tought, in my use cases, all data will be reloaded anyway. So, no principle difference, wich method will be used.
from memoizee.
@puzrin Thanks for clarification. I get the point, only if data is accessed again and close to expiry date, it's wise to refresh it in background and push forward expiry date (so likely future access won't have to wait).
Indeed if data is requested frequently it's beneficial, and it's more optimized approach than refreshing any cached value when it's expired, very good point, I'll make reFetch to work exactly that way.
The only difference to what you propose is that I would probably do re-fetch on calls made some time before expiry date rather than still serving cached value to those that were slightly later, I think it would be more what you expect. Serving value obtained 10 seconds ago when e.g. maxAge is set to 8 seconds is controversial. Let me know if I still miss something.
from memoizee.
Yeah, -(10-20%) before expire will make the same effect, as +(10-20%) after expire (in real life). No principle difference, but pre-fetching looks more logical, than post-loading.
Probably, this interval could be tuned via options, but i guess, 10% default will be "good for all".
from memoizee.
Thank you! It landed in v0.2.2. I used -33% as default, but it's customizable
from memoizee.
Thanks!
from memoizee.
I looked code a bit. Didn't understood, how do you resolve race conditions? If cache is about to expire, and has multiple async gets, will they cause multiple refresh requests? The same question for start state, when cache is empty.
from memoizee.
@puzrin async logic is separated from maxAge/preFetch logic.
When we're working with asynchronous function, cache hit occurs here: https://github.com/medikoo/memoize/blob/master/lib/ext/async.js#L37
preFetch logic that occurs on cache hit is here:
https://github.com/medikoo/memoize/blob/master/lib/ext/max-age.js#L48
Race condition is prevented by L49 and L51. There's no way that value would be reFetched multiple times.
Another call to memoized function at L55 invokes https://github.com/medikoo/memoize/blob/master/lib/ext/max-age.js#L23-27 again, so preFetch configuration is reinitialized then.
from memoizee.
Got it, thanks. I was not sure about preFetchCache
intention. Probably, it worth to rename it to preFetchLock
or similar, to reduce possible confusion. I fact, that's not cache, but singleton locks.
from memoizee.
Good hint, actually preFetchCache
holds either timeout id or race condition lock, but still you're right it deservers a better name. I'll fix that. Thanks!
from memoizee.
Related Issues (20)
- Cannot find module 'event-emitter' HOT 3
- Dependency on "D" renders this useless HOT 4
- Doesn't work with snowpack. HOT 3
- Is not caching non-promise returning calls the intended behavior? HOT 1
- Promise rejections not cleared immediately from cache HOT 2
- Callback for cache access HOT 5
- setter method HOT 1
- How to deal with functions taking dict args? HOT 6
- Rollup fails to bundle memoizee correctly HOT 6
- feat: let default nomalizer be more general HOT 1
- replace `es5-ext` with `core-js@^3` HOT 2
- Cannot import memoizee HOT 3
- Memoizing a function without arguments HOT 1
- Allow `maxAgeSinceAccess` in addition to `maxAge` HOT 11
- Why is the memoizee so slow? HOT 2
- Is there a way to dynamically configure the size? HOT 7
- Feature Request: Wouldn't it be good if we could use a Redis backend? HOT 2
- max option does not work with promise option HOT 1
- Option to return prior cached value on update failure HOT 5
- Package is showing a vulnerability HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memoizee.