Skip to content

feat(utils): ExpiringMapCache + StoreCache (scavenged from openclaw) - #3

Merged
kobie3717 merged 1 commit into
mainfrom
feat/cache-utilities
Apr 27, 2026
Merged

kobie3717 merged 1 commit into
mainfrom
feat/cache-utilities

Conversation

@kobie3717

Copy link
Copy Markdown
Owner

Two-tier session file caching and generic TTL cache patterns extracted from openclaw/openclaw codebase to replace ad-hoc Map+setTimeout patterns.

ExpiringMapCache:

  • Generic TTL cache with automatic expiration
  • Background prune sweeps expired entries
  • Injectable clock for testing
  • Tests: 9 tests covering TTL, pruning, stop(), size()

SessionStoreCache (stores/store-cache.ts):

  • Two-tier cache: raw file content + parsed JSON
  • Fingerprint-based invalidation (mtime + size)
  • LRU eviction at maxEntries (default 100)
  • Injectable filesystem adapter for testing
  • Tests: 9 tests covering cache hits/misses, LRU, invalidation

Changes:

  • Enhanced src/cache/expiring-map.ts (already existed)
  • Added src/stores/store-cache.ts (new)
  • Added src/tests/store-cache.test.ts (9 tests)
  • Enhanced src/tests/expiring-map.test.ts (9 tests)
  • Updated package-lock.json (dev dependencies)

All 210 tests pass. No breaking changes to public API.

Description

Brief description of changes.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • Tests pass (npm test)
  • Types check (npm run typecheck)
  • Lint passes (npm run lint)
  • Added/updated tests for changes
  • Updated documentation if needed
  • Follows conventional commit format

Two-tier session file caching and generic TTL cache patterns extracted from
openclaw/openclaw codebase to replace ad-hoc Map+setTimeout patterns.

ExpiringMapCache:
- Generic TTL cache with automatic expiration
- Background prune sweeps expired entries
- Injectable clock for testing
- Tests: 9 tests covering TTL, pruning, stop(), size()

SessionStoreCache (stores/store-cache.ts):
- Two-tier cache: raw file content + parsed JSON
- Fingerprint-based invalidation (mtime + size)
- LRU eviction at maxEntries (default 100)
- Injectable filesystem adapter for testing
- Tests: 9 tests covering cache hits/misses, LRU, invalidation

Changes:
- Enhanced src/cache/expiring-map.ts (already existed)
- Added src/stores/store-cache.ts (new)
- Added src/__tests__/store-cache.test.ts (9 tests)
- Enhanced src/__tests__/expiring-map.test.ts (9 tests)
- Updated package-lock.json (dev dependencies)

All 210 tests pass. No breaking changes to public API.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@kobie3717
kobie3717 merged commit 6520278 into main Apr 27, 2026
0 of 2 checks passed
@kobie3717
kobie3717 deleted the feat/cache-utilities branch April 27, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant