Skip to content

fix(cache): back the response cache with Redis on cache-manager v7#108

Merged
entrius merged 2 commits into
testfrom
fix/redis-response-cache
May 17, 2026
Merged

fix(cache): back the response cache with Redis on cache-manager v7#108
entrius merged 2 commits into
testfrom
fix/redis-response-cache

Conversation

@anderdc
Copy link
Copy Markdown
Collaborator

@anderdc anderdc commented May 17, 2026

Summary

The response cache module was copied from das-gittensor, which runs @nestjs/cache-manager v2 / cache-manager v5. das-github-mirror is on v3 / cache-manager v7 (Keyv-based), where the config shape changed — so the copied config was silently broken on arrival (commit b771271):

  • v3 reads the store list from stores (plural, Keyv instances). The singular store key was ignored, so Redis was never used.
  • v3 reads the entry TTL from the top-level ttl. The ttl nested inside redisStore({ ttl }) never reached the cache.

Net effect in production: an in-memory cache with no expiry. Cached GET responses were pinned from process start and served stale until the next restart — observed ~20h stale on /api/v1/miners/:id/issues.

This PR:

  • Replaces cache-manager-redis-yet (v5-era, incompatible with cache-manager v7) with @keyv/redis, the Keyv-era Redis adapter.
  • Passes stores: [Keyv] + top-level ttl — the shape v3 actually reads.
  • Namespaces cache keys apicache to stay clear of BullMQ's bull:* keyspace on the shared Redis instance.
  • Adds an error listener so a Redis outage degrades to an uncached request instead of crashing the process on an unhandled EventEmitter error.
  • Types the factory return as CacheModuleOptions instead of any — the type hole that let the wrong shape compile silently.

Related Issues

None.

Type of Change

  • Bug fix

Testing

  • npm run build — passes
  • npx eslint / prettier --check — clean
  • Compiled output confirms the @keyv/redis wiring (stores: [Keyv], apicache namespace)
  • Runtime TTL/Redis behavior verifies on deploy (the deploy also clears the current broken in-memory cache)

Checklist

  • I have read the Contributing Guide
  • Code builds without errors
  • New and existing tests pass (if applicable) — no cache tests exist in the repo
  • Documentation updated (if applicable) — n/a
  • No unnecessary dependencies added — net swap: −cache-manager-redis-yet, +@keyv/redis (the correct adapter for the installed cache-manager version)

Note

This fixes the application cache only. A reverse-proxy cache fronting mirror.gittensor.io (the x-cache response header) is a separate layer outside this repo and should be checked independently.

The cache module was copied from das-gittensor (@nestjs/cache-manager
v2 / cache-manager v5). das-github-mirror is on v3 / cache-manager v7
(Keyv-based), where the config shape changed, so the copied config was
broken on arrival in b771271:

- v3 reads the store list from `stores` (plural Keyv instances); the
  singular `store` key was ignored, so Redis was never used.
- v3 reads the entry TTL from top-level `ttl`; the `ttl` nested inside
  `redisStore({ ttl })` never reached the cache.

Production therefore ran an in-memory cache with no expiry — GET
responses were pinned from process start and served stale until the
next restart (~20h stale observed on /api/v1/miners/:id/issues).

- Replace cache-manager-redis-yet (v5-era, incompatible with v7) with
  @keyv/redis.
- Pass `stores: [Keyv]` + top-level `ttl`.
- Namespace cache keys `apicache`, clear of BullMQ's `bull:*`.
- Add a store error listener so a Redis blip degrades to an uncached
  request instead of crashing the process.
- Type the factory return as CacheModuleOptions (was `any`).
@xiao-xiao-mao xiao-xiao-mao Bot added the bug Something isn't working label May 17, 2026
The previous commit's lockfile was generated with npm 11 (local), which
CI's npm 10 (Node 20) rejected as out of sync — `npm ci` reported the
chokidar subtree missing from the lock. Regenerated with npm 10 so the
lockfile format matches CI; `npm ci` now passes locally under npm 10.
@entrius entrius merged commit 8cf63f3 into test May 17, 2026
2 checks passed
@entrius entrius deleted the fix/redis-response-cache branch May 17, 2026 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants