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
Stop using signals to cache objects #137
Comments
I feel bad about this, but here's what I'm about to do. In Then, for the user/group checks, we only need check that the user ID is in the The "all" caches will cache lists of these dicts, instead of whatever they have now. Finally, signal handlers will be set up on post_save, pre_delete, post_delete, and m2m_changed, for the following:
The assumption is that changing flags is very rare compared to checking them, so we'd much rather incur these queries predictably on change, instead of on access. If any of that sends people screaming for the hills... Or if it seems I've forgotten anything here, let me know. |
I'll also update the admin to not use the queryset delete—or to at least overwrite all the caches if it does. |
+1 |
Is there any update on this feature? When this feature is complete the 0.10.2 should be released? |
- Removes all signal handlers, fixes #137. - Adds Cls.get_all() methods, fixes #142. - Moves caching globally into Cls.get() and Cls.get_all(), fixes #170, fixes #160, fixes #77. - Adds managers to invalidate ALL_* cache keys on create. - Adds a new delete admin action to invalidate cache. - Adds Flag.is_active_for_user, fixes #186. - Uses delete_many to flush cache, fixes #158. - Fixes cache invalidation in override_*, fixes #163.
Using the signal handlers to cache objects and clear the cache is way too complicated and is even worse when you want to cache misses. It's also very hard to reason about and has been a source of some pain in the past.
The strategy I've been using internally lately is much, much simpler:
This works great when, like in waffle, most access is by one particular attribute, in this case the names. This doesn't impact the user API at all, only the internals of some methods.
It's a little more complex with the sub-keys for user and group lists on flags, but I think by being clever with the
_cache_key
and including themodified
datetime, we can make that invalidation automatic and easier.The text was updated successfully, but these errors were encountered: