TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/whiskeysockets/Baileys/llms.txt
Use this file to discover all available pages before exploring further.
makeCacheableSignalKeyStore function wraps a SignalKeyStore with an in-memory cache to reduce database queries and improve performance.
Function Signature
Parameters
The underlying key store to add caching to. Can be any implementation of
SignalKeyStore.Optional logger to trace cache operations. Logs events like:
- Cache hits/misses
- Number of items loaded from store
- Cache update operations
Optional custom cache implementation. If not provided, uses a default
NodeCache with:- TTL: 5 minutes (300 seconds)
- useClones: false (stores references, not copies)
- deleteOnExpire: true (automatically removes expired entries)
Returns
A cached wrapper around the original store with the same interface
Usage Example
How It Works
Cache Keys
Cache keys are generated using a combination of type and ID:Get Operation Flow
- Check cache for each requested ID
- Collect cache misses in
idsToFetcharray - Query store only for missing IDs
- Update cache with fetched items
- Return combined results (cached + fetched)
Set Operation Flow
- Update cache with all provided data
- Write to store (pass-through to underlying implementation)
- Log operation if logger provided
Thread Safety
All cache operations are protected by a mutex to prevent race conditions:Performance Benefits
Reduced Database Queries
Reduced Database Queries
Frequently accessed keys (like sessions) are served from memory, significantly reducing database load.
Lower Latency
Lower Latency
In-memory cache access is orders of magnitude faster than disk/database access.
Automatic Expiration
Automatic Expiration
Default 5-minute TTL ensures cache doesn’t grow unbounded while keeping hot data available.
Custom Cache Implementation
You can provide a custom cache that implements theCacheStore interface:
Example: Redis Cache
Related
- SignalKeyStore - Base key store interface
- useMultiFileAuthState - File-based auth state
- AuthenticationState - Complete authentication state documentation