@crossplatformai/cache
v0.4.2
Published
Shared cache module for CrossPlatform.ai projects
Readme
@crossplatformai/cache
Shared cache adapters for CrossPlatform.ai projects.
This package stays frameworkless and infrastructure-light. Apps own the actual Redis client and inject it into the adapter.
What this package provides
RedisCacheAdapterfor Redis-backed cache behaviorMemoryCacheAdapterfor tests and local in-memory usageCacheRedisClienttype for the minimal injected Redis client contract
Package boundary
This package owns:
- cache adapter behavior
- key prefixing behavior
- TTL handling
- counter, set, and hash helpers
- the minimal Redis client interface used by the adapter
This package does not own:
- Redis connection configuration
- Redis client lifecycle policy beyond best-effort connect support
- app-specific cache key naming
- auth or device business logic
- framework request/response handling
Installation
pnpm add @crossplatformai/cache redisredis is a peer dependency. The consuming app installs and owns it.
Usage
Redis adapter
import { createClient } from 'redis';
import { RedisCacheAdapter } from '@crossplatformai/cache';
const redis = createClient({
url: process.env.REDIS_URL,
});
export const cache = new RedisCacheAdapter({
client: redis,
keyPrefix: 'cache:',
});Memory adapter
import { MemoryCacheAdapter } from '@crossplatformai/cache';
const cache = new MemoryCacheAdapter();
await cache.set('health', 'ok', 60);
const value = await cache.get('health');Import paths
@crossplatformai/cache- main exports@crossplatformai/cache/adapters- adapter exports@crossplatformai/cache/types- cache types
Redis client contract
RedisCacheAdapter accepts an injected client matching CacheRedisClient.
This is intentionally a narrow contract so apps can:
- use the official
redispackage - control connection lifecycle themselves
- swap compatible implementations if needed
Publishing model
This package currently publishes raw TypeScript source.
That is intentional for now. Consuming repos are expected to use toolchains that can consume package TypeScript directly.
Testing
pnpm test
pnpm check-types
pnpm lintLicense
See LICENSE.
