Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/1.x/adaptive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: Adaptive Caching
---

# Adaptive Caching

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.

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.

```php
$relay = new Relay(
host: 'localhost',
port: 6379,
context: [
'adaptive-cache' => [
// Number of horizontal cells. Ideally this should scale with the
// number of unique keys in the database. Supported values: 512 - 2^31.
'width' => 100_000,

// Number of vertical cells. Supported values: 1 - 8.
'depth' => 6,

// Minimum number of events (reads + writes) before Relay
// will use the ratio to determine if a key should remain cached.
// Using a negative number will invert this and Relay won't cache
// a key until its seen at least that many events for the key.
'minEvents' => 10,

// Minimum ratio of reads to writes of a key to remain
// cached (positive events) or be cached (negative events).
'minRatio' => 5.0,
],
],
);
```
5 changes: 3 additions & 2 deletions docs/1.x/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ curl -O "https://builds.r2.relay.so/v0.9.1/relay.stub.php"

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

- `Local` indicates the method _does not_ communicate with Redis
- `Server` indicates the method that _may_ communicate with Redis
- `Local` indicates the method _does not_ communicate with Redis/Valkey
- `Server` indicates the method that _may_ communicate with Redis/Valkey
- `RedisCommand` indicates the method represents a [command](https://redis.io/commands/)
- `ValkeyCommand` indicates the method represents a [command](https://valkey.io/commands/)
- `Cached` indicates the method _may_ use in-memory caching
3 changes: 2 additions & 1 deletion docs/1.x/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ To disable all in-memory caching and memory allocation `relay.maxmemory` can be
| `relay.locks.cache` | `mutex` | Locking mechanism used for the in-memory cache (databases). Supported values: `spinlock`, `mutex`, `adaptive-mutex` |
| `relay.default_pconnect` | `1` | Default to using a persistent connection when calling `connect()`. |
| `relay.initial_readers` | `128` | The number of epoch readers allocated on startup. |
| `relay.invalidation_poll_freq` | `5` | How often (in microseconds) Relay should proactively check the connection for invalidation messages from Redis. |
| `relay.invalidation_poll_freq` | `5` | How often (in microseconds) Relay should proactively check the connection for invalidation messages from Redis/Valkey. |
| `relay.loglevel` | `off` | Whether Relay should log debug information. Supported levels: `debug`, `verbose`, `error`, `off` |
| `relay.logfile` | | The path to the file in which information should be logged, if logging is enabled. |
| `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` |
| `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` |
| `relay.cluster.timeout` | | The maximum number of seconds Relay will wait while establishing connection to a single cluster node. |
| `relay.cluster.read_timeout` | | The maximum number of seconds Relay will wait while reading from a cluster node. |
| `relay.cluster.slot_cache_expiry` | | The TTL of the cluster slot cache. |
| `relay.session.locking_enabled` | `0` | Whether to enable session locking to avoid race conditions and keep session data consistent across requests. |
| `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. |
| `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. |
Expand Down
2 changes: 1 addition & 1 deletion docs/1.x/connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ title: Connections

## Overview

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.
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.

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

Expand Down
5 changes: 3 additions & 2 deletions docs/1.x/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
- [Integrations](/docs/1.x/integrations)
- ##### The Basics
- [Connections](/docs/1.x/connections)
- [Eviction](/docs/1.x/eviction)
- [Events](/docs/1.x/events)
- [Tables](/docs/1.x/tables)
- [Ratios](/docs/1.x/events)
- [Options](/docs/1.x/options)
- [Eviction](/docs/1.x/eviction)
- [Tables](/docs/1.x/tables)
- ##### Digging Deeper
- [Performance](/docs/1.x/performance)
- [Compatibility](/docs/1.x/compatibility)
Expand Down