Module: GraphQL::Cache

Defined in:
lib/graphql/cache.rb,
lib/graphql/cache/key.rb,
lib/graphql/cache/field.rb,
lib/graphql/cache/rails.rb,
lib/graphql/cache/fetcher.rb,
lib/graphql/cache/marshal.rb,
lib/graphql/cache/version.rb,
lib/graphql/cache/deconstructor.rb

Defined Under Namespace

Classes: Deconstructor, Fetcher, Field, Key, Marshal, Rails

Constant Summary collapse

VERSION =
'0.3.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cacheObject

An object that must conform to the same API as ActiveSupport::Cache::Store

Returns:

  • (Object)

    Defaults to Rails.cache in a Rails environment



14
15
16
# File 'lib/graphql/cache.rb', line 14

def cache
  @cache
end

.expiryInteger

Global default cache key expiration time in seconds.

Returns:

  • (Integer)

    Default: 5400 (90 minutes)



18
19
20
# File 'lib/graphql/cache.rb', line 18

def expiry
  @expiry
end

.forceBoolean

When truthy, override all caching (force evalutaion of resolvers)

Returns:

  • (Boolean)

    Default: false



22
23
24
# File 'lib/graphql/cache.rb', line 22

def force
  @force
end

.loggerLogger

Logger instance to use when logging cache hits/misses.

Returns:

  • (Logger)


26
27
28
# File 'lib/graphql/cache.rb', line 26

def logger
  @logger
end

.namespaceString

Global namespace for keys

Returns:

  • (String)

    Default: "GraphQL::Cache"



30
31
32
# File 'lib/graphql/cache.rb', line 30

def namespace
  @namespace
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Provides for initializer syntax

GraphQL::Cache.configure do |c|
  c.namespace = 'MyNamespace'
end

Yields:

  • (_self)

Yield Parameters:



39
40
41
# File 'lib/graphql/cache.rb', line 39

def configure
  yield self
end

.use(schema_def, options: {}) ⇒ Object

Called by plugin framework in graphql-ruby to bootstrap necessary instrumentation and tracing tie-ins



52
53
54
55
# File 'lib/graphql/cache.rb', line 52

def self.use(schema_def, options: {})
  fetcher = ::GraphQL::Cache::Fetcher.new
  schema_def.instrument(:field, fetcher)
end