You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently this gem allows values to be cached until the expire, when this happens a new value is generated, cached and returned. This means that every ttl one user/client/connection needs to wait for the cache to refresh.
It would be great if you could specify the time after which a value is stale (time to stale?). Where stale means the value can still be used but a new version should be generated in the background.
Ex:
defget_highscoreCache.new(tts: 5.minutes,ttl: 10.minutes){get_resource('https://example.org/api/highscore.json')}end# snip…snip…snipputsget_highscore# first time, fetches datasleep1.minuteputsget_highscore# use cachesleep5.minutesputsget_highscore# cache is stale, method returns immediately background job fetches new dataputsget_highscore# background job might still be busy, stale cache still used, no second job startedsleep5.secondsputsget_highscore# new data is used, timers resetsleep15.minutesputsget_highscore# value completely expired, method blocks to fetch new data.
This way values are kept up-to-date and no user/client/connection has is blocked every once and a while.
Two more ideas:
Pluggable backend, defaulting to Thread.new. If this gem is used in an eventmachine environment eventmachine should be used.
Automatic stale. If you measure the average time a refresh takes, you can predict when a new version should be fetch. ex: tts = ttl - (measured_time*2) (this should be disabled by default).
Cheers,
—Koen
The text was updated successfully, but these errors were encountered:
Currently this gem allows values to be cached until the expire, when this happens a new value is generated, cached and returned. This means that every
ttl
one user/client/connection needs to wait for the cache to refresh.It would be great if you could specify the time after which a value is stale (time to stale?). Where stale means the value can still be used but a new version should be generated in the background.
Ex:
This way values are kept up-to-date and no user/client/connection has is blocked every once and a while.
Two more ideas:
Thread.new
. If this gem is used in an eventmachine environment eventmachine should be used.tts = ttl - (measured_time*2)
(this should be disabled by default).Cheers,
—Koen
The text was updated successfully, but these errors were encountered: