Module: CacheQL
- Defined in:
- lib/cacheql.rb,
lib/cacheql/railtie.rb,
lib/cacheql/version.rb,
lib/cacheql/record_loader.rb,
lib/cacheql/resolve_wrapper.rb,
lib/cacheql/association_loader.rb,
lib/cacheql/field_instrumentation.rb,
lib/cacheql/polymorphic_key_loader.rb
Overview
Defined Under Namespace
Classes: AssociationLoader, FieldInstrumentation, PolymorphicKeyLoader, Railtie, RecordLoader, ResolveWrapper
Constant Summary collapse
- VERSION =
"0.2.0"
Class Method Summary collapse
-
.fetch(cacheable_fields, query, variables, &block) ⇒ Object
Query-level caching, for any cacheable_fields.
Class Method Details
.fetch(cacheable_fields, query, variables, &block) ⇒ Object
Query-level caching, for any cacheable_fields
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/cacheql.rb', line 14 def self.fetch(cacheable_fields, query, variables, &block) document = GraphQL.parse(query) cacheables = document.definitions.map { |definition| definition.selections.map(&:name) }.flatten & cacheable_fields if cacheables.present? cache_key = [ CacheQL::Railtie.config.global_key, 'result', Digest::SHA256.hexdigest(document.to_query_string + variables.to_s) ] CacheQL::Railtie.config.cache.fetch(cache_key, expires_in: CacheQL::Railtie.config.expires_range.sample.minutes) do block.call(document) end else block.call(document) end end |