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.6.0'.freeze

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

.loggerLogger

Logger instance to use when logging cache hits/misses.

Returns:

  • (Logger)


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

def logger
  @logger
end

.namespaceString

Global namespace for keys

Returns:

  • (String)

    Default: "GraphQL::Cache"



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

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:



35
36
37
# File 'lib/graphql/cache.rb', line 35

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



47
48
49
50
# File 'lib/graphql/cache.rb', line 47

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