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
* CSC POC ontop of Parser
* add csc file that weren't merged after patch
* address review comments
* nits to try and fix github
* last change from review
* Update client-side cache and improve documentation
* Add client side caching RESP3 validation
* Add documentation for RESP and unstableResp3 options
* Add comprehensive cache statistics
The `CacheStats` class provides detailed metrics like hit/miss counts,
load success/failure counts, total load time, and eviction counts.
It also offers derived metrics such as hit/miss rates, load failure rate,
and average load penalty. The design is inspired by Caffeine.
`BasicClientSideCache` now uses a `StatsCounter` to accumulate these
statistics, exposed via a new `stats()` method. The previous
`cacheHits()` and `cacheMisses()` methods have been removed.
A `recordStats` option (default: true) in `ClientSideCacheConfig`
allows disabling statistics collection.
---------
Co-authored-by: Shaya Potter <[email protected]>
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
+
// `cache.stats()` returns a `CacheStats` object with comprehensive statistics.
146
+
conststatistics=cache.stats();
147
+
148
+
// Key metrics:
149
+
consthits=statistics.hitCount; // Number of cache hits
150
+
constmisses=statistics.missCount; // Number of cache misses
151
+
consthitRate=statistics.hitRate(); // Cache hit rate (0.0 to 1.0)
152
+
153
+
// Many other metrics are available on the `statistics` object, e.g.:
0 commit comments