You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -235,6 +235,24 @@ of sending a `QUIT` command to the server, the client can simply close the netwo
235
235
client.destroy();
236
236
```
237
237
238
+
### Client Side Caching
239
+
240
+
Node Redis v5 adds support for [Client Side Caching](https://redis.io/docs/manual/client-side-caching/), which enables clients to cache query results locally. The Redis server will notify the client when cached results are no longer valid.
241
+
242
+
```typescript
243
+
// Enable client side caching with RESP3
244
+
const client =createClient({
245
+
RESP: 3,
246
+
clientSideCache: {
247
+
ttl: 0, // Time-to-live (0 = no expiration)
248
+
maxEntries: 0, // Maximum entries (0 = unlimited)
249
+
evictPolicy: "LRU"// Eviction policy: "LRU" or "FIFO"
250
+
}
251
+
});
252
+
```
253
+
254
+
See the [V5 documentation](./docs/v5.md#client-side-caching) for more details and advanced usage.
255
+
238
256
### Auto-Pipelining
239
257
240
258
Node Redis will automatically pipeline requests that are made during the same "tick".
Node Redis v5 adds support for [Client Side Caching](https://redis.io/docs/manual/client-side-caching/), which enables clients to cache query results locally. The server will notify the client when cached results are no longer valid.
96
+
97
+
Client Side Caching is only supported with RESP3.
98
+
99
+
## Usage
100
+
101
+
There are two ways to implement client side caching:
102
+
103
+
### Anonymous Cache
104
+
105
+
```javascript
106
+
constclient=createClient({
107
+
RESP:3,
108
+
clientSideCache: {
109
+
ttl:0, // Time-to-live in milliseconds (0 = no expiration)
110
+
maxEntries:0, // Maximum entries to store (0 = unlimited)
111
+
evictPolicy:"LRU"// Eviction policy: "LRU" or "FIFO"
112
+
}
113
+
});
114
+
```
115
+
116
+
In this instance, the cache is managed internally by the client.
117
+
118
+
### Controllable Cache
119
+
120
+
```javascript
121
+
import { BasicClientSideCache } from'redis';
122
+
123
+
constcache=newBasicClientSideCache({
124
+
ttl:0,
125
+
maxEntries:0,
126
+
evictPolicy:"LRU"
127
+
});
128
+
129
+
constclient=createClient({
130
+
RESP:3,
131
+
clientSideCache: cache
132
+
});
133
+
```
134
+
135
+
With this approach, you have direct access to the cache object for more control:
136
+
137
+
```javascript
138
+
// Manually invalidate keys
139
+
cache.invalidate(key);
140
+
141
+
// Clear the entire cache
142
+
cache.clear();
143
+
144
+
// Get cache metrics
145
+
consthits=cache.cacheHits();
146
+
constmisses=cache.cacheMisses();
147
+
```
148
+
149
+
## Pooled Caching
150
+
151
+
Client side caching also works with client pools. For pooled clients, the cache is shared across all clients in the pool:
Copy file name to clipboardExpand all lines: packages/redis/README.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -234,6 +234,23 @@ of sending a `QUIT` command to the server, the client can simply close the netwo
234
234
```typescript
235
235
client.destroy();
236
236
```
237
+
### Client Side Caching
238
+
239
+
Node Redis v5 adds support for [Client Side Caching](https://redis.io/docs/manual/client-side-caching/), which enables clients to cache query results locally. The Redis server will notify the client when cached results are no longer valid.
240
+
241
+
```typescript
242
+
// Enable client side caching with RESP3
243
+
const client =createClient({
244
+
RESP: 3,
245
+
clientSideCache: {
246
+
ttl: 0, // Time-to-live (0 = no expiration)
247
+
maxEntries: 0, // Maximum entries (0 = unlimited)
248
+
evictPolicy: "LRU"// Eviction policy: "LRU" or "FIFO"
249
+
}
250
+
});
251
+
```
252
+
253
+
See the [V5 documentation](../../docs/v5.md#client-side-caching) for more details and advanced usage.
0 commit comments