Skip to content

Commit b6ed411

Browse files
author
Daniel Hartnell
committed
Introduce option to enable cache lookup monitoring
1 parent 1e33358 commit b6ed411

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

lib/graphql/fragment_cache.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module FragmentCache
2525
class << self
2626
attr_reader :cache_store
2727
attr_accessor :enabled
28+
attr_accessor :monitoring_enabled
2829
attr_accessor :namespace
2930
attr_accessor :default_options
3031

@@ -87,6 +88,7 @@ def verify_interpreter_and_analysis!(schema_defn)
8788

8889
self.cache_store = MemoryStore.new
8990
self.enabled = true
91+
self.monitoring_enabled = false
9092
self.namespace = "graphql"
9193
self.default_options = {}
9294
self.skip_cache_when_query_has_errors = false

lib/graphql/fragment_cache/fragment.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ def read_multi(fragments)
3030
FragmentCache.cache_store.read_multi(*cache_keys)
3131
end
3232

33-
begin
34-
fragments.map do |fragment|
35-
cache_lookup_event(
36-
cache_key: fragment.cache_key,
37-
operation_name: fragment.context.query.operation_name,
38-
path: fragment.path,
39-
cache_hit: cache_keys_to_values.key?(fragment.cache_key)
40-
)
33+
if GraphQL::FragmentCache.monitoring_enabled
34+
begin
35+
fragments.map do |fragment|
36+
cache_lookup_event(
37+
cache_key: fragment.cache_key,
38+
operation_name: fragment.context.query.operation_name,
39+
path: fragment.path,
40+
cache_hit: cache_keys_to_values.key?(fragment.cache_key)
41+
)
42+
end
43+
rescue
44+
# Allow cache_lookup_event to fail when we do not have all of the requested attributes
4145
end
42-
rescue
43-
# Allow cache_lookup_event to fail when we do not have all of the requested attributes
4446
end
4547

4648
# Fragmenst without values or with renew_cache: true in their context will have nil values like the read method

0 commit comments

Comments
 (0)