Module: GraphQL::Cache
- Defined in:
- lib/graphql/cache.rb,
lib/graphql/cache/field.rb,
lib/graphql/cache/rails.rb,
lib/graphql/cache/builder.rb,
lib/graphql/cache/marshal.rb,
lib/graphql/cache/version.rb,
lib/graphql/cache/middleware.rb
Defined Under Namespace
Classes: Builder, Field, Marshal, Middleware, Rails
Constant Summary collapse
- VERSION =
'0.2.5'
Class Attribute Summary collapse
-
.cache ⇒ Object
An object that must conform to the same API as ActiveSupport::Cache::Store.
-
.expiry ⇒ Integer
Global default cache key expiration time in seconds.
-
.force ⇒ Boolean
When truthy, override all caching (force evalutaion of resolvers).
-
.logger ⇒ Logger
Logger instance to use when logging cache hits/misses.
-
.namespace ⇒ String
Global namespace for keys.
Class Method Summary collapse
-
.configure {|_self| ... } ⇒ Object
Provides for initializer syntax.
-
.fetch(key, config: {}, &block) ⇒ Object
Fetches/writes a value for
keyfrom the cache.
Class Attribute Details
.cache ⇒ Object
An object that must conform to the same API as ActiveSupport::Cache::Store
13 14 15 |
# File 'lib/graphql/cache.rb', line 13 def cache @cache end |
.expiry ⇒ Integer
Global default cache key expiration time in seconds.
17 18 19 |
# File 'lib/graphql/cache.rb', line 17 def expiry @expiry end |
.force ⇒ Boolean
When truthy, override all caching (force evalutaion of resolvers)
21 22 23 |
# File 'lib/graphql/cache.rb', line 21 def force @force end |
.logger ⇒ Logger
Logger instance to use when logging cache hits/misses.
25 26 27 |
# File 'lib/graphql/cache.rb', line 25 def logger @logger end |
.namespace ⇒ String
Global namespace for keys
29 30 31 |
# File 'lib/graphql/cache.rb', line 29 def namespace @namespace end |
Class Method Details
.configure {|_self| ... } ⇒ Object
Provides for initializer syntax
GraphQL::Cache.configure do |c|
c.namespace = 'MyNamespace'
end
38 39 40 |
# File 'lib/graphql/cache.rb', line 38 def configure yield self end |
.fetch(key, config: {}, &block) ⇒ Object
Fetches/writes a value for key from the cache
Always evaluates the block unless config[:metadata][:cache] is truthy
56 57 58 59 60 |
# File 'lib/graphql/cache.rb', line 56 def self.fetch(key, config: {}, &block) return block.call unless config[:metadata][:cache] Marshal[key].read(config, &block) end |