Add cache tags support #498
Open
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.
The original cache implementation relies on two main parts: scope and query.
Quite often we use scoping as a policy-based access control for listing actions like
index
. With Graphiti it is easily achieved by making#base_scope
context-aware (e.g. like checking a requesting user role and restricting access to certain entities for non-admins). The problem is that it is only represented via changes in the DB query object (we have different cache keys for different scopes since they result in different queries). One of the side effects is that Graphiti has no idea about it and cache debugger stubbornly states lots and lots of cache misses (it associates cache keys with the request info that doesn't include any info from the request context).The idea behind this PR is simple: enable cache tagging with a value returned from a resource instance method (that can access request context). This method name has to be passed as a symbol argument to the
cache_resource
resource class method alongsideexpires_in
argument.