Documentation Index Fetch the complete documentation index at: https://docs.agentfront.dev/llms.txt
Use this file to discover all available pages before exploring further.
Installation
npm install @frontmcp/plugin-cache
Basic Usage
import { FrontMcp } from ' @frontmcp/sdk ' ;
import { CachePlugin } from ' @frontmcp/plugin-cache ' ;
@ FrontMcp ({
plugins : [
new CachePlugin ({
ttl : 60000 // 1 minute default TTL
})
]
})
export class MyServer {}
Configuration
new CachePlugin ({
// Default TTL in milliseconds
ttl : 60000 ,
// Storage backend
storage : ' memory ' , // or 'redis'
// Redis configuration (if storage is 'redis')
redis : {
url : ' redis://localhost:6379 '
},
// Maximum cache size (memory only)
maxSize : 1000 ,
// Cache key prefix
prefix : ' mcp:cache: '
})
Cache specific tools:
@ Tool ({
name : ' getUser ' ,
cache : {
ttl : 300000 , // 5 minutes
key : ( params ) => ` user: ${ params . id } `
}
})
async getUser ({ id }) {
return await db . users . findById ( id );
}
Cache Invalidation
Manual Invalidation
@ Tool ({ name : ' updateUser ' })
async updateUser ({ id , data }) {
await db . users . update ( id , data );
// Invalidate cache
await this . cache . invalidate ( ` user: ${ id } ` );
return { success : true };
}
Pattern Invalidation
// Invalidate all user caches
await this . cache . invalidatePattern ( ' user:* ' );
Cache Strategies
Read-Through
const user = await this . cache . get ( ` user: ${ id } ` , async () => {
return await db . users . findById ( id );
}, { ttl : 60000 });
Write-Through
await this . cache . set ( ` user: ${ id } ` , user );
await db . users . update ( id , user );
Redis Backend
For production, use Redis:
import { CachePlugin , RedisCache } from ' @frontmcp/plugins ' ;
import Redis from ' ioredis ' ;
const redis = new Redis ( process . env . REDIS_URL );
new CachePlugin ({
storage : new RedisCache ( redis )
})
Cache Events
const cache = new CachePlugin ({
onHit : ( key ) => console . log ( ` Cache hit: ${ key } ` ),
onMiss : ( key ) => console . log ( ` Cache miss: ${ key } ` ),
onEvict : ( key ) => console . log ( ` Cache evict: ${ key } ` )
});
Next Steps
Remember Plugin Persistent memory
CodeCall Plugin Code execution