Skip to content

Commit

Permalink
enterprise-1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
rmosolgo committed Aug 30, 2024
1 parent a7ecad1 commit a5e12e8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG-enterprise.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

### Bug Fix

# 1.5.1 (30 Aug 2024)

- ObjectCache: Add `connection_pool:` support

# 1.5.0 (26 Jul 2024)

- ObjectCache: Add Dalli backend for Memcached
Expand Down
52 changes: 30 additions & 22 deletions guides/object_cache/redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,6 @@ index: 3

`GraphQL::Enterprise::ObjectCache` requires a Redis connection to store cached responses. Unlike `OperationStore` or rate limiters, this Redis instance should be configured to evict keys as needed.

## Data Structure

Under the hood, `ObjectCache` stores a mapping of queries and objects. Additionally, there are back-references from objects to queries that reference them. In general, like this:

```
"query1:result" => '{"data":{...}}'
"query1:objects" => ["obj1:v1", "obj2:v2"]
"query2:result" => '{"data":{...}}'
"query2:objects" => ["obj2:v2", "obj3:v1"]
"obj1:v1" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj2:v2" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj3:v1" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj1:v1:queries" => ["query1"]
"obj2:v2:queries" => ["query1", "query2"]
"obj3:v1:queries" => ["query2"]
```

These mappings enable proper clean-up when queries or objects are expired from the cache. Additionally, whenever `ObjectCache` finds incomplete data in storage (for example, a necessary key was evicted), then it invalidates the whole query and re-runs it.

## Memory Management

Memory consumption is hard to estimate since it depends on how many queries the cache receives, how many objects those queries reference, how big the response is for those queries, and how long the fingerprints are for each object and query. To manage memory, configure the Redis instance with a `maxmemory` and `maxmemory-policy` directive, for example:
Expand All @@ -54,3 +32,33 @@ use GraphQL::Enterprise::ObjectCache, redis_cluster: Redis::Cluster.new(...)
```

Under the hood, it uses query fingerprints as [hash tags](https://redis.io/docs/latest/operate/oss_and_stack/reference/cluster-spec/#hash-tags) and each cached result has its own set of object metadata.

## Connection Pool

`ObjectCache` also supports [ConnectionPool](https://github.com/mperham/connection_pool). To use it, pass `connection_pool:`:

```ruby
use GraphQL::Enterprise::ObjectCache, connection_pool: ConnectionPool.new(...) { ... }
```

## Data Structure

Under the hood, `ObjectCache` stores a mapping of queries and objects. Additionally, there are back-references from objects to queries that reference them. In general, like this:

```
"query1:result" => '{"data":{...}}'
"query1:objects" => ["obj1:v1", "obj2:v2"]
"query2:result" => '{"data":{...}}'
"query2:objects" => ["obj2:v2", "obj3:v1"]
"obj1:v1" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj2:v2" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj3:v1" => { "fingerprint" => "...", "id" => "...", "type_name" => "..." }
"obj1:v1:queries" => ["query1"]
"obj2:v2:queries" => ["query1", "query2"]
"obj3:v1:queries" => ["query2"]
```

These mappings enable proper clean-up when queries or objects are expired from the cache. Additionally, whenever `ObjectCache` finds incomplete data in storage (for example, a necessary key was evicted), then it invalidates the whole query and re-runs it.
1 change: 1 addition & 0 deletions guides/pro/checksums/graphql-enterprise-1.5.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f83113767fb51f584f0d27b34f44fccc8ca05fab61e150bd6dd9098c9b3aef41751c4337ca994e2b78486fdd71c623a6d24da985d3bcee983a33c7a798a25e2d

0 comments on commit a5e12e8

Please sign in to comment.