Comments (4)
Added this feature in #50
from graphql-ruby-fragment_cache.
Hi @bbugh! The feature sounds helpful, I wonder if it makes sense to use more general approach and pass custom key via options
:
class CacheKeyBuilder
key = "#{schema_cache_key}/#{query_cache_key}"
key = "#{key}/#{options[:object_cache_key]}" if options[:object_cache_key]
Digest::SHA1.hexdigest ...
end
cache_fragment(object_cache_key: where_class.whatever_we_want) { where_class.do_something }
from graphql-ruby-fragment_cache.
That seems great! That also prevents having to change object_key in three places.
I think you'd have to also check for the options[:object_cache_key]
:
key = "#{schema_cache_key}/#{query_cache_key}"
key = "#{key}/#{options[:object_cache_key]}" if options[:object_cache_key]
Digest::SHA1.hexdigest("#{schema_cache_key}/#{query_cache_key}").then do |base_key|
next base_key unless object || options[:object_cache_key]
"#{base_key}/#{object_key(object)}"
end
Maybe a little more readable:
def build
Digest::SHA1.hexdigest("#{schema_cache_key}/#{query_cache_key}").then do |base_key|
if options[:object_cache_key]
"#{base_key}/#{options[:object_cache_key]}"
elsif object
"#{base_key}/#{object_key(object)}"
else
base_key
end
end
end
Does that seem fine? I can make a PR for this and README changes.
from graphql-ruby-fragment_cache.
Yeah, looks pretty good! I'll be happy to review this PR
from graphql-ruby-fragment_cache.
Related Issues (20)
- graphql-ruby 2.0.18 causing tracer breaking changes HOT 2
- Schema.instrument is deprecated
- Deprecation warning for tracer HOT 1
- Rails 7.1 deprecation notice for `cache_format_version` in Rails `test` environment HOT 4
- Way to conditionally use fragment cache? HOT 4
- Federated queries including cached fields raises an error HOT 2
- Recyclable Cache Keys? HOT 3
- [Unable to use] graphql-ruby-fragment_cache + action_policy-graphql HOT 5
- Fragment cache somtimes returns null despite cached data loading initially HOT 20
- Package not working with graphql-ruby > 1.12.10 HOT 2
- Per request cache? HOT 1
- Namespace issue HOT 2
- How do I expire a cached collection when a sub model changes? HOT 3
- "Failed to implement Post.id" when returning cached RawValue in resolvers HOT 1
- Specs fail when testing cached fields HOT 3
- Make the cache key human-readable HOT 3
- [Question] Programmatically Clear Entire Cache HOT 7
- Upgrade to 1.18.0 version error HOT 2
- Cache connection type using multi HOT 3
- Clarification on cache_key options HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-ruby-fragment_cache.