Skip to content

Commit 82d00cc

Browse files
committed
close
1 parent 28510de commit 82d00cc

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

cache/docs/DETAILED.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ These are typically pre-installed on Linux/macOS systems. If missing, install vi
4444
- **Max Bytes**: 1GB per worker (1,000,000,000 bytes) (configurable)
4545
- **TTL (Time-To-Live)**: 5 minutes default, 24 hours in production (300,000ms or 86,400,000ms)
4646
- **Storage Mode**: PM2 Cluster Cache with 'all' replication mode (full cache copy on each worker, synchronized automatically)
47-
- **Stats Sync**: Background interval every 5 seconds via setInterval (stats may be up to 5s stale across workers)
47+
- **Stats Tracking**: Atomic counters for sets/evictions/invalidations (race-condition free), local counters for hits/misses (synced every 5 seconds)
4848
- **Eviction**: LRU (Least Recently Used) eviction implemented with deferred background execution via setImmediate() to avoid blocking cache.set() operations
4949

5050
### Environment Variables
@@ -281,7 +281,10 @@ Cache Key: gogGlosses:https://example.org/manuscript/123:50:0
281281
### Cache Statistics (`GET /v1/api/cache/stats`)
282282
**Handler**: `cacheStats`
283283

284-
**Stats Synchronization**: Stats are aggregated across all PM2 workers via background interval (every 5 seconds). When you request `/cache/stats`, you receive the most recently synchronized stats, which may be up to 5 seconds stale. This is acceptable for monitoring dashboards and provides fast response times (~2ms) without blocking.
284+
**Stats Tracking**:
285+
- **Atomic counters** (sets, evictions, invalidations): Updated immediately in cluster cache to prevent race conditions
286+
- **Local counters** (hits, misses): Tracked locally per worker, synced to cluster cache every 5 seconds for performance
287+
- **Aggregation**: Stats endpoint aggregates from all workers, accurate within 5 seconds for hits/misses
285288

286289
Returns cache performance metrics:
287290
```json

cache/docs/SHORT.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Returns aggregated stats from all PM2 workers:
9393
}
9494
```
9595

96-
**Note**: Stats synchronized via background interval (every 5 seconds). May be up to 5 seconds stale.
96+
**Stats Accuracy**: Critical counters (sets, evictions, invalidations) use atomic updates for accuracy. Hit/miss counters are synced every 5 seconds for performance.
9797

9898
### Clear Cache
9999
```
@@ -135,9 +135,7 @@ The cache is completely transparent:
135135
- Cache entries replicated across all worker instances
136136
- Consistent cache hits regardless of which worker handles request
137137
- Automatic synchronization via PM2's inter-process communication
138-
- **Stats Synchronization**: Background interval syncs stats every 5 seconds
139-
- Stats may be up to 5 seconds stale (acceptable for monitoring)
140-
- Fast response time (<10ms) for `/cache/stats` endpoint
138+
- **Stats Tracking**: Atomic counters for sets/evictions/invalidations (race-condition free), local counters for hits/misses (synced every 5 seconds)
141139
- Version chains properly handled for RERUM's object versioning model
142140
- No manual cache management required
143141

0 commit comments

Comments
 (0)