cache_stream_set
Cache ordered string chunks from an LLM token stream as Redis list elements for later replay.
Instructions
Cache a list of string chunks (e.g. LLM token stream) via Redis RPUSH. Each chunk is stored as a separate list element under cachly:stream:{key}. Replay with cache_stream_get.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instance_id | Yes | UUID of the cache instance | |
| key | Yes | Cache key | |
| chunks | Yes | Ordered list of string chunks | |
| ttl | No | TTL in seconds for the stored list (optional) |
Implementation Reference
- src/handlers/cache.ts:606-617 (handler)Handler implementation for cache_stream_set. Destructures args (instance_id, key, chunks, ttl), validates chunks is a non-empty array, deletes any existing list at cachly:stream:{key}, then uses a Redis pipeline to RPUSH all chunks and optionally sets a TTL. Returns a success message with chunk count, TTL info, and total char size.
case 'cache_stream_set': { const { instance_id, key, chunks, ttl } = args as { instance_id: string; key: string; chunks: string[]; ttl?: number }; if (!Array.isArray(chunks) || chunks.length === 0) return '⚠️ No chunks provided.'; const redis = await getConnection(instance_id); const listKey = `cachly:stream:${key}`; await redis.del(listKey); const pipe = redis.pipeline(); for (const chunk of chunks) pipe.rpush(listKey, chunk); if (ttl && ttl > 0) pipe.expire(listKey, ttl); await pipe.exec(); return `✅ **cache_stream_set** – ${chunks.length} chunk(s) stored.\n Key: \`${key}\`\n${ttl ? ` TTL: ${ttl}s\n` : ''} Total size: ${chunks.reduce((a, c) => a + c.length, 0)} chars`; } - src/tools.ts:1232-1248 (schema)Schema/registration definition for cache_stream_set tool. Defines name, description, and inputSchema with required fields: instance_id (string), key (string), chunks (string array), and optional ttl (number).
{ name: 'cache_stream_set', description: 'Cache a list of string chunks (e.g. LLM token stream) via Redis RPUSH. ' + 'Each chunk is stored as a separate list element under cachly:stream:{key}. ' + 'Replay with cache_stream_get.', inputSchema: { type: 'object', properties: { instance_id: { type: 'string', description: 'UUID of the cache instance' }, key: { type: 'string', description: 'Cache key' }, chunks: { type: 'array', items: { type: 'string' }, description: 'Ordered list of string chunks' }, ttl: { type: 'number', description: 'TTL in seconds for the stored list (optional)' }, }, required: ['instance_id', 'key', 'chunks'], }, }, - src/handlers/cache.ts:19-24 (registration)Registration of cache_stream_set in the CACHE_TOOL_NAMES set, which is used by the dispatch logic in handleCacheTool to route tool calls to the correct case branch.
export const CACHE_TOOL_NAMES = new Set([ 'cache_get', 'cache_set', 'cache_delete', 'cache_exists', 'cache_ttl', 'cache_keys', 'cache_stats', 'semantic_search', 'detect_namespace', 'cache_warmup', 'index_project', 'cache_mset', 'cache_mget', 'cache_lock_acquire', 'cache_lock_release', 'cache_stream_set', 'cache_stream_get', ]);