npm.io
1.5.2 • Published 6d ago

@frontmcp/plugin-cache

Licence
Apache-2.0
Version
1.5.2
Deps
2
Size
60 kB
Vulns
0
Weekly
2.0K
Stars
144

@frontmcp/plugin-cache

Cache plugin for FrontMCP - provides automatic tool result caching with support for Redis, Vercel KV, and in-memory storage.

Installation

npm install @frontmcp/plugin-cache

Usage

import { CachePlugin } from '@frontmcp/plugin-cache';
import { App } from '@frontmcp/sdk';

@App({
  plugins: [CachePlugin],
})
class MyApp {}

Features

  • Multiple storage backends: Redis, Vercel KV, or in-memory
  • Automatic TTL management: Configure cache expiration
  • Tool result caching: Automatically cache tool execution results
  • Configurable cache keys: Customize how cache keys are generated

Configuration

In-Memory (Default)
import { CachePlugin } from '@frontmcp/plugin-cache';

@App({
  plugins: [
    CachePlugin.init({
      type: 'memory',
      defaultTTL: 300, // TTL in seconds (default: 1 day)
    }),
  ],
})
class MyApp {}
Redis
import { CachePlugin } from '@frontmcp/plugin-cache';

@App({
  plugins: [
    CachePlugin.init({
      type: 'redis',
      defaultTTL: 300,
      config: {
        host: 'localhost',
        port: 6379,
        password: process.env.REDIS_PASSWORD, // optional
        db: 0, // optional
      },
    }),
  ],
})
class MyApp {}
Redis Client (Reuse Existing)
import { CachePlugin } from '@frontmcp/plugin-cache';
import { Redis } from 'ioredis';

const redis = new Redis({ host: 'localhost', port: 6379 });

@App({
  plugins: [
    CachePlugin.init({
      type: 'redis-client',
      client: redis,
      defaultTTL: 300,
    }),
  ],
})
class MyApp {}
Global Store

Use the store configuration from @FrontMcp decorator:

import { CachePlugin } from '@frontmcp/plugin-cache';

@App({
  plugins: [
    CachePlugin.init({
      type: 'global-store', // Uses redis/vercel-kv from FrontMcp config
    }),
  ],
})
class MyApp {}

License

Apache-2.0

Keywords