Task/dogpile orm event invalidation - #3029
Closed
whabanks wants to merge 20 commits into
Closed
Conversation
- Add dogpile-cache to pyproject.toml - Set up a basic, redis-backed, dogpile cache region with `distributed_lock` turned on and `thread_local_lock` turned off to play nicely in a threaded environment - Implement a custom cache-key generation strategy to try and match our current cache key patterns - Implement dogpile cached version of `dao_fetch_service_by_id` - Invalidate cache whenever a service's settings are updated
Instead of implementing per-model/per-dao method invalidation strategies, implement a broader strategy to allow us to, for example, invalidate all service related keys when a service is updated.
- Implemented basic json serializer / deserializer instead of pickling/unpickling values - Updates the key structure to reduce redundancy and logically group keys by entity - Updated tests
- Remove explicit expiration time from annotations, let region configuration propagate - Ensure tests use the json serializer/deserializer - Removed explicit call to `invalidate_group_keys` for now - Default the cache config's REDIS_URL to localhost if not set
Implement a basic ORM event driven invalidation strategy for service keys. Listeners are attached to the sqlalchemy session `after_flush`, `after_commit` and `after_rollback` events which will invalidate service cache keys under the following conditions - `service` entity is updated/deleted - `service_permissions` are updated - `service_user` list is added to, updated, or removed from
Member
|
I am concerned that this approach (and the other PR too but maybe slightly less) might be difficult to scale, i.e. every time a developer wants certain cache to be added, they would have to make sure proper specific events fire, and that these are for service IDs, is that right? And when we want to add a cache specific to users, and templates, and keys, and etc.. we'd have also to add specific glue code for these? The cache isn't generic enough to handle these automatically? |
8 tasks
Contributor
Author
5 tasks
Contributor
Author
|
Closing in favour of this PR because I royally forked up the commit history on this PR with a prior rebase. Given there's is still much work to do I'd like to be merciful to reviewers. Will capture the current conversation in that PR as well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary | Résumé
This PR experimentally implements an ORM-event driven invalidation strategy for
Serviceentities. Rather than calling an explicitinvalidate_service_cache_keys()function on every path that mutates service and service related data; we instead listen toafter_flush,after_commit, andafter_rollbacksqlalchemy session events, weaving cache invalidation calls into that process. (similar in nature to aspect oriented programming)Note:
it looks messy currently because it was rebased with 3011 in order to be testable. The bulk of the changes are in:
This nets us:
Related Issues | Cartes liées
Test instructions | Instructions pour tester la modification
Release Instructions | Instructions pour le déploiement
None.
Reviewer checklist | Liste de vérification du réviseur