Skip to content

Commit 90d660c

Browse files
authored
Adaptive cache docs (#17)
* wip * Update adaptive.md * Update configuration.md
1 parent 8551d51 commit 90d660c

5 files changed

Lines changed: 45 additions & 6 deletions

File tree

docs/1.x/adaptive.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Adaptive Caching
3+
---
4+
5+
# Adaptive Caching
6+
7+
Relay supports an adaptive caching mechanism to only cache keys that meet a read-write ratio to aid applications that suffer from cache thrashing, e.g. WordPress sites.
8+
9+
The configuration for the adaptive cache is highly individual to an application and should ideally be benchmarked. At the very least match the `width` of the cache to the unique number of keys that exist in the cache.
10+
11+
```php
12+
$relay = new Relay(
13+
host: 'localhost',
14+
port: 6379,
15+
context: [
16+
'adaptive-cache' => [
17+
// Number of horizontal cells. Ideally this should scale with the
18+
// number of unique keys in the database. Supported values: 512 - 2^31.
19+
'width' => 100_000,
20+
21+
// Number of vertical cells. Supported values: 1 - 8.
22+
'depth' => 6,
23+
24+
// Minimum number of events (reads + writes) before Relay
25+
// will use the ratio to determine if a key should remain cached.
26+
// Using a negative number will invert this and Relay won't cache
27+
// a key until its seen at least that many events for the key.
28+
'minEvents' => 10,
29+
30+
// Minimum ratio of reads to writes of a key to remain
31+
// cached (positive events) or be cached (negative events).
32+
'minRatio' => 5.0,
33+
],
34+
],
35+
);
36+
```

docs/1.x/api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ curl -O "https://builds.r2.relay.so/v0.9.1/relay.stub.php"
2020

2121
All methods have PHP attributes to provide some metadata which can be inspected at runtime using the Reflection APIs.
2222

23-
- `Local` indicates the method _does not_ communicate with Redis
24-
- `Server` indicates the method that _may_ communicate with Redis
23+
- `Local` indicates the method _does not_ communicate with Redis/Valkey
24+
- `Server` indicates the method that _may_ communicate with Redis/Valkey
2525
- `RedisCommand` indicates the method represents a [command](https://redis.io/commands/)
26+
- `ValkeyCommand` indicates the method represents a [command](https://valkey.io/commands/)
2627
- `Cached` indicates the method _may_ use in-memory caching

docs/1.x/configuration.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ To disable all in-memory caching and memory allocation `relay.maxmemory` can be
4141
| `relay.locks.cache` | `mutex` | Locking mechanism used for the in-memory cache (databases). Supported values: `spinlock`, `mutex`, `adaptive-mutex` |
4242
| `relay.default_pconnect` | `1` | Default to using a persistent connection when calling `connect()`. |
4343
| `relay.initial_readers` | `128` | The number of epoch readers allocated on startup. |
44-
| `relay.invalidation_poll_freq` | `5` | How often (in microseconds) Relay should proactively check the connection for invalidation messages from Redis. |
44+
| `relay.invalidation_poll_freq` | `5` | How often (in microseconds) Relay should proactively check the connection for invalidation messages from Redis/Valkey. |
4545
| `relay.loglevel` | `off` | Whether Relay should log debug information. Supported levels: `debug`, `verbose`, `error`, `off` |
4646
| `relay.logfile` | | The path to the file in which information should be logged, if logging is enabled. |
4747
| `relay.cluster.seeds` | | The list of cluster nodes addresses grouped by cluster name, which will be used to initialize each cluster, encoded as URL query string, e.g. `cluster1[]=127.0.0.1:7000&cluster2[]=127.0.0.1:8000` |
4848
| `relay.cluster.auth` | | The list of credentials for each cluster, encoded as URL query string. Password string or username/password pairs may be used, e.g. `cluster1=secret&cluster2[]=username&cluster2[]=secret` |
4949
| `relay.cluster.timeout` | | The maximum number of seconds Relay will wait while establishing connection to a single cluster node. |
5050
| `relay.cluster.read_timeout` | | The maximum number of seconds Relay will wait while reading from a cluster node. |
51+
| `relay.cluster.slot_cache_expiry` | | The TTL of the cluster slot cache. |
5152
| `relay.session.locking_enabled` | `0` | Whether to enable session locking to avoid race conditions and keep session data consistent across requests. |
5253
| `relay.session.lock_expire` | `0` | The number of seconds while Relay will try to acquire lock. When value is zero or negative `max_execution_time` will be used. |
5354
| `relay.session.lock_retries` | `0` | The number of attempts Relay will try to acquire lock. If value is zero or negative `100` will be used to be compatible with PhpRedis. |

docs/1.x/connections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ title: Connections
88

99
## Overview
1010

11-
Relay treats all connections as persistent by default, meaning each PHP worker will open its own dedicated connection to Redis and it will be reused between invocations.
11+
Relay treats all connections as persistent by default, meaning each PHP worker will open its own dedicated connection to Redis/Valkey and it will be reused between invocations.
1212

1313
Establishing connections with Relay can be done just like using PhpRedis:
1414

docs/1.x/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
- [Integrations](/docs/1.x/integrations)
88
- ##### The Basics
99
- [Connections](/docs/1.x/connections)
10+
- [Eviction](/docs/1.x/eviction)
1011
- [Events](/docs/1.x/events)
11-
- [Tables](/docs/1.x/tables)
12+
- [Ratios](/docs/1.x/events)
1213
- [Options](/docs/1.x/options)
13-
- [Eviction](/docs/1.x/eviction)
14+
- [Tables](/docs/1.x/tables)
1415
- ##### Digging Deeper
1516
- [Performance](/docs/1.x/performance)
1617
- [Compatibility](/docs/1.x/compatibility)

0 commit comments

Comments
 (0)