-
Notifications
You must be signed in to change notification settings - Fork 24
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
A robust, hopefully production-ready caching implementation #31
Conversation
…essary for class method aliasing.
This implements `cache_key`, `updated_at` and `touch` at the class level simply by delegating to the most recently updated document in the collection.
This one change that fixes the two issues you describe is extremely blog-worthy. It clarifies in a major way why the next version of Garner is so much better than the previous version of Garner. You could call |
A robust, hopefully production-ready caching implementation
I like SafeCacheKey, although @dblock's argument is compelling. The |
@joeyAghion: Sorry, @dblock: I wasn't sure about SRT at first, but I think that once again, @mzikherman's ever-relevant GIF has me convinced. |
The big question is whether to spell |
@joeyAghion: Actually, I did define that method, incredibly. I'll send a quick pull request to revert that. |
to: @dblock
cc: @joeyAghion
Sorry for the big PR. I promise the next one will be more concise. The big change here was replacing the
CacheKey
strategy with a more robustSafeCacheKey
strategy (better name suggestions welcome 😉) which provides the same (or better) performance than Garner 0.3.3. TheCacheKey
strategy was OK — in fact, it fully mirrored the caching performance of Rails 4 — but it suffered from two critical flaws:SafeCacheKey
strategy.cache_key
defined. So you can't bind to a class. This pull request solves that by proxyingModel.cache_key
toModel.latest.cache_key
.Some more minor, or structural changes:
invalidate_garner_caches
. Motivation: In the specific case of theTouch
invalidation strategy, it's redundant and even possibly harmful for us to calltouch
on documents during Mongoid callbacks.SafeCacheKey
always uses the actual database state as truth, it probably wasn't an issue here, but could very well be an issue for other strategies, like theIdentityMap
strategy I'm working on. So thanks again for bringing up the corner case.Base
classes. There's a minor need now (seeapply_on_callback?
), and conceivably a major need later, for inheritable behavior in strategy groups.Pending any changes you guys suggest, I think this is ready for production. (Famous last words.) Let's
!