Skip to content

Commit ceefe42

Browse files
author
Daniel Hartnell
committed
Adds documentation for cache monitoring
1 parent b6ed411 commit ceefe42

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,30 @@ Cache processing can be disabled if needed. For example:
446446
GraphQL::FragmentCache.enabled = false if Rails.env.test?
447447
```
448448

449+
## Cache lookup monitoring
450+
451+
It may be useful to capture cache lookup events. When monitoring is enabled, the `cache_key`, `operation_name`, `path` and a boolean indicating a cache hit or miss will be sent to a `cache_lookup_event` method. This method can be implemented in your application to handle the event.
452+
453+
Example handler defined in a Rails initializer:
454+
455+
```ruby
456+
module GraphQL
457+
module FragmentCache
458+
class Fragment
459+
def self.cache_lookup_event(**args)
460+
# Monitoring such as incrementing a cache hit counter metric
461+
end
462+
end
463+
end
464+
end
465+
```
466+
467+
Like managing caching itself, monitoring can be enabled if needed. It is disabled by default. For example:
468+
469+
```ruby
470+
GraphQL::FragmentCache.monitoring_enabled = true
471+
```
472+
449473
## Limitations
450474

451475
1. `Schema#execute`, [graphql-batch](https://github.com/Shopify/graphql-batch) and _graphql-ruby-fragment_cache_ do not [play well](https://github.com/DmitryTsepelev/graphql-ruby-fragment_cache/issues/45) together. The problem appears when `cache_fragment` is _inside_ the `.then` block:

0 commit comments

Comments
 (0)