uber-archive / backbone-api-client-redis Goto Github PK
View Code? Open in Web Editor NEWMixins that add Redis caching on top of backbone-api-client
License: Other
Mixins that add Redis caching on top of backbone-api-client
License: Other
Sometimes, actions at one-off endpoints affect your data. While this is non-atomic and disgusting itself, it happens. To make sure we keep our cache accurate at these points, we should expose the cache deletion logic from callApiClient
as clearCache
.
clearCache(method, options, cb);
Currently, we only cache read
responses and invalidate on everything else. However, some server support sending back the resource upon create/update. As a result, we should cache/serve that data.
Unfortunately, we guarantee requests are stored against the hash of their request options. As a result, it is impossible for us to predict what save data would line up with, if at all.
Additionally, this hash is used to switch between server upgrades easily (e.g. new attributes on request options).
Please discuss possible options in this thread.
While request-redis-cache
is great, it is a little too naive. I would love to support stale-fresh-cache
which is intended to work via:
Let's work with an example TTL (fresh = 30 minutes, stale = 60 minutes).
If we have no cached information, get it and cache it for 60 minutes.
If there is cached information, send back whatever we have.
In addition, check the TTL. If the TTL is over 30 minutes (e.g. the cache has turned stale), fetch the information in the background and update our cache.
The benefit to this mechanism is it prevents completely running out of data to serve without sacrificing performance. Additionally, it guarantees the data will expire at some point. However, it is still possible to cache stampede =/
Internally, we use twemproxy
which does not support keys
which renders our current deletion pattern useless.
https://github.com/twitter/twemproxy/blob/v0.3.0/notes/redis.md
Some possible solutions:
hget/hset
) and figure out if we can expire there (pretty sure no)Currently, it is a little annoying that we more/less lock in callApiClient
functionality before allowing caching mixin. Should we be doing this and is there a better way (e.g. via sync
overrides)?
For reference, we are currently structuring it this way to pick up changes from adjustApiClientOptions
which could affect parameters and thus the hash for the request. We want the hash to be as sensitive to what is actually sent out/important as possible.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.