Every CacheService in the backtest-kit library stores a mapping from a compound context key — composed ofDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/theonetrade/backtest-kit-redis-mongo-docker/llms.txt
Use this file to discover all available pages before exploring further.
exchangeName, strategyName, and symbol — to the MongoDB _id of the corresponding document. These mappings are held in Redis with no expiry (-1 TTL), so they persist for the full lifetime of the Redis instance. Each service is built by extending BaseMap, a factory-generated base class that provides ten generic Redis hash-map operations scoped to a fixed key namespace.
BaseMap
Factory-generated Redis map with 10 methods. All keys are namespaced under a
connectionKey prefix. Iteration uses SCAN batches of 100 to avoid blocking the Redis event loop.CacheService pattern
Each service extends
BaseMap with a fixed connectionKey (e.g., signal_cache), a TTL of -1, and three domain-specific methods: hasXxxId, getXxxId, and setXxxId.BaseMap
BaseMap is produced by the factory() helper. It accepts a connectionKey namespace string and an optional ttlExpireSeconds value as constructor arguments, then returns a class whose every Redis key is prefixed with connectionKey:.
Key namespace
Every key stored in Redis follows the patternconnectionKey:subkey. The _getItemKey(key) helper constructs this full Redis key internally — you never need to call it directly. For example, a SignalCacheService entry for the context ccxt-exchange:jan_2026_strategy:TRXUSDT is stored under:
Methods
Writes
value to the Redis key connectionKey:key. If ttlExpireSeconds is greater than zero, the key is set with an expiry. When ttlExpireSeconds is -1, no expiry is applied and the key persists indefinitely.Reads the value stored at
connectionKey:key. Returns null when the key does not exist or when key is passed as null.Removes the key
connectionKey:key from Redis. A no-op if the key does not exist.Returns
true if connectionKey:key exists in Redis, false otherwise.Deletes every key that matches the glob pattern
connectionKey:*. Internally uses a SCAN-based cursor loop (batch size ITERATOR_BATCH_SIZE = 100) to avoid issuing a blocking KEYS command on large datasets.Returns all
[key, value] pairs under the connectionKey namespace as an array. Uses the same SCAN-based approach as clear().Async generator that yields
[key, value] pairs one batch at a time. Prefer this over toArray() when the namespace may contain a large number of keys.Async generator that yields only the key portion (with the
connectionKey: prefix stripped) of every entry in the namespace.Async generator that yields only the stored values for every entry in the namespace.
Returns the total count of keys in the
connectionKey namespace. Uses SCAN internally rather than DBSIZE so it only counts keys belonging to this map’s prefix.TTL and expiry
The default TTL for aBaseMap instance is DEFAULT_TTL_EXPIRE_SECONDS = 300 (5 minutes). All 15 CacheServices override this by passing -1 to the constructor, which disables expiry entirely. Cache entries survive as long as the Redis instance is running and are only removed by an explicit delete(), clear(), or an external Redis flush.
SCAN-based iteration (
ITERATOR_BATCH_SIZE = 100) is used by clear, toArray, iterate, keys, values, and size. This ensures Redis is never blocked for more than the time it takes to process 100 keys, regardless of how large the namespace grows.CacheService pattern
Each CacheService extendsBaseMap with a hardcoded connectionKey and a TTL of -1. On top of the ten inherited methods, every service adds exactly three domain-specific methods.
The three domain methods
Every CacheService exposes the same trio of methods, named after its domain entity:| Method | Description |
|---|---|
hasXxxId(symbol, strategyName, exchangeName) | Returns true if the compound context key exists in Redis. Delegates to super.has(_cacheKey(...)). |
getXxxId(symbol, strategyName, exchangeName) | Returns the cached MongoDB document ID string, or null on a miss. Delegates to super.get(_cacheKey(...)). |
setXxxId(row: IXxxRowDoc) | Extracts symbol, strategyName, exchangeName, and _id from the document, builds the compound key, and calls super.set(key, id). Returns the stored ID. |
Cache key format
The compound subkey is always assembled in the orderexchangeName:strategyName:symbol:
exchangeName) first, which groups all entries for a given exchange together when scanning, and the most-selective segment (symbol) last.
All 15 CacheServices use TTL
-1 — entries never expire automatically. If you flush a CacheService (e.g., via clear()) the paired DbService’s findByContext will fall back to MongoDB on the next call and re-populate the cache automatically.All 15 CacheServices
| CacheService | Redis Key Prefix | Cache Key Pattern |
|---|---|---|
candleCacheService | candle_cache | candle_cache:{exchangeName}:{strategyName}:{symbol} |
signalCacheService | signal_cache | signal_cache:{exchangeName}:{strategyName}:{symbol} |
scheduleCacheService | schedule_cache | schedule_cache:{exchangeName}:{strategyName}:{symbol} |
riskCacheService | risk_cache | risk_cache:{exchangeName}:{strategyName}:{symbol} |
partialCacheService | partial_cache | partial_cache:{exchangeName}:{strategyName}:{symbol} |
breakevenCacheService | breakeven_cache | breakeven_cache:{exchangeName}:{strategyName}:{symbol} |
storageCacheService | storage_cache | storage_cache:{exchangeName}:{strategyName}:{symbol} |
notificationCacheService | notification_cache | notification_cache:{exchangeName}:{strategyName}:{symbol} |
logCacheService | log_cache | log_cache:{exchangeName}:{strategyName}:{symbol} |
measureCacheService | measure_cache | measure_cache:{exchangeName}:{strategyName}:{symbol} |
intervalCacheService | interval_cache | interval_cache:{exchangeName}:{strategyName}:{symbol} |
memoryCacheService | memory_cache | memory_cache:{exchangeName}:{strategyName}:{symbol} |
recentCacheService | recent_cache | recent_cache:{exchangeName}:{strategyName}:{symbol} |
stateCacheService | state_cache | state_cache:{exchangeName}:{strategyName}:{symbol} |
sessionCacheService | session_cache | session_cache:{exchangeName}:{strategyName}:{symbol} |
Accessing CacheServices
All 15 cache services are available from theioc object: