This repository was archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcache.rb
59 lines (50 loc) · 1.64 KB
/
cache.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require 'graphql/cache/version'
require 'graphql/cache/field'
require 'graphql/cache/key'
require 'graphql/cache/marshal'
require 'graphql/cache/fetcher'
require 'graphql/cache/field_extension'
require 'graphql/cache/patch/connection_extension'
module GraphQL
module Cache
class << self
# An object that must conform to the same API as ActiveSupport::Cache::Store
# @return [Object] Defaults to `Rails.cache` in a Rails environment
attr_accessor :cache
# Global default cache key expiration time in seconds.
# @return [Integer] Default: 5400 (90 minutes)
attr_accessor :expiry
# Logger instance to use when logging cache hits/misses.
# @return [Logger]
attr_accessor :logger
# Global namespace for keys
# @return [String] Default: "GraphQL::Cache"
attr_accessor :namespace
# Provides for initializer syntax
#
# ```
# GraphQL::Cache.configure do |c|
# c.namespace = 'MyNamespace'
# end
# ```
def configure
yield self
end
end
# Default configuration
@expiry = 5400
@namespace = 'graphql'
# Called by plugin framework in graphql-ruby to
# bootstrap necessary instrumentation and tracing
# tie-ins
def self.use(schema_def, options: {})
# please, use GraphQL::Cache::FieldExtension if use Interpreter mode
if Gem::Version.new(GraphQL::VERSION) >= Gem::Version.new('1.9.0.pre3')
fetcher = ::GraphQL::Cache::Fetcher.new
schema_def.instrument(:field, fetcher)
end
end
end
end
require 'graphql/cache/rails' if defined?(::Rails::Engine)