@ai-sdk-tools/cache weekly downloads statistics
By ai-sdk-tools (5 listings) · npm · AI SDKs
Simple caching wrapper for AI SDK tools - cache expensive tool executions with zero configuration
@ai-sdk-tools/cache has 4,244 recorded weekly downloads on npm, a decrease of 4.6% over the past 30 days, ranking #1597 of 3,247 tracked listings.
About @ai-sdk-tools/cache
@ai-sdk-tools/cache
Universal caching wrapper for AI SDK tools. Cache expensive tool executions with zero configuration - works with regular tools, streaming tools, and artifacts.
Why Cache Tools?
AI agents repeatedly call expensive tools:
- Same API calls across conversation turns (weather, translations)
- Heavy calculations with identical parameters (financial analysis)
- Database queries that don't change (user profiles, company data)
- Streaming tools with complex artifact data (charts, metrics)
Caching provides:
- 10x faster responses for repeated requests
- 80% cost reduction by avoiding duplicate calls
- Smooth agent conversations with instant cached results
- Complete data preservation - streaming, artifacts, everything
Installation
npm install @ai-sdk-tools/cache
# or
bun add @ai-sdk-tools/cache
Quick Start
Basic Usage (LRU Cache)
import { tool } from 'ai';
import { createCached } from '@ai-sdk-tools/cache';
import { z } from 'zod';
// Your expensive tool
const expensiveWeatherTool = tool({
description: 'Get weather data from API',
parameters: z.object({
location: z.string(),
}),
execute: async ({ location }) => {
// Expensive API call
const response = await fetch(`https://api.weather.com/v1/current?location=${location}`);
return response.json();
},
});
// Create cached function (uses LRU by default)
const cached = createCached();
// Wrap with caching - that's it! 🎉
const weatherTool = cached(expensiveWeatherTool);
// Use normally with AI SDK
const result = await generateText({
model: openai('gpt-4o'),
tools: { weather: weatherTool },
messages: [{ role: 'user', content: 'Weather in NYC?' }],
});
Result: First call hits the API, subsequent calls return instantly from cache!
Redis/Upstash Cache (Production)
import { Redis } from "@upstash/redis";
import { createCached } from '@ai-sdk-tools/cache';
// Just pass your Redis client!
const cached = createCached({
cache: Redis.fromEnv(), // That's it!
ttl: 30 * 60 * 1000, // 30 minutes
});
const weatherTool = cached(expensiveWeatherTool);
Standard Redis
import Redis from "redis";
import { createCached } from '@ai-sdk-tools/cache';
const cached = createCached({
cache: Redis.createClient({ url: "redis://localhost:6379" }),
keyPrefix: "my-app:",
ttl: 30 * 60 * 1000,
});
IORedis
import IORedis from "ioredis";
import { createCached } from '@ai-sdk-tools/cache';
const cached = createCached({
cache: new IORedis("redis://localhost:6379"),
keyPrefix: "my-app:",
ttl: 30 * 60 * 1000,
});
Universal Redis Support
Works with any Redis client that implements:
get(key: string): Promise<string | null>set(key: string, value: string): Promise<void>del(key: string): Promise<void>setex?(key: string, seconds: number, value: string): Promise<void>(optional)
Supported clients:
- ✅ Upstash Redis -
@upstash/redis - ✅ Standard Redis -
redis - ✅ IORedis -
ioredis - ✅ Redis Clusters - Any cluster client
- ✅ Custom Redis clients - As long as they implement the interface
Configuration Options
const cached = createCached({
cache?: any; // Redis client (optional, defaults to LRU)
keyPrefix?: string; // Cache key prefix (default: "ai-tools-cache:")
ttl?: number; // Time to live in ms (default: 10min LRU, 30min Redis)
debug?: boolean; // Debug logging (default: false)
onHit?: (key: string) => void; // Cache hit callback
onMiss?: (key: string) => void; // Cache miss callback
});
Multi-Tenant Apps (Context-Aware Caching)
For apps with user/team context, just add getContext to the cache config:
import { cached } from '@ai-sdk-tools/cache';
// Your app's context system (could be React context, global state, etc.)
const burnRateAnalysisTool = tool({
description: 'Analyze burn rate',
parameters: z.object({
from: z.string(),
to: z.string(),
}),
execute: async ({ from, to }) => {
// Your app's way of getting current user/team context
const currentUser = getCurrentUser(); // or useUser(), getSession(), etc.
return await db.getBurnRate({
teamId: currentUser.teamId, // ← Context used here
from,
to,
});
},
});
// Cache with context - that's it!
export const cachedBurnRateTool = cached(burnRateAnalysisTool, {
cacheKey: () => {
const currentUser = getCurrentUser();
return `team:${currentUser.teamId}:user:${currentUser.id}`;
},
ttl: 30 * 60 * 1000, // 30 minutes
});
Result: Cache keys automatically include teamId and userId - no collisions between users/teams!
Reusable Cache Configuration
For consistent setup across your app, create a configured cache function:
// src/lib/cache.ts
import { cached as baseCached, createCacheBackend } from '@ai-sdk-tools/cache';
import { getContext } from '@/ai/context';
// Create cache backend
const cacheBackend = createCacheBackend({
type: 'redis',
redis: {
client: Redis.createClient({ url: process.env.REDIS_URL }),
keyPrefix: 'my-app:',
},
});
// Export configured cache function
export function cached<T extends Tool>(tool: T, options = {}) {
return baseCached(tool, {
store: cacheBackend,
cacheKey: () => {
const currentUser = getCurrentUser();
return `team:${currentUser.teamId}:user:${currentUser.id}`;
},
ttl: 30 * 60 * 1000, // 30 minutes
debug: process.env.NODE_ENV === 'development',
...options,
});
}
// Throughout your app
import { cached } from '@/lib/cache';
export const myTool = cached(originalTool);
Streaming Tools with Artifacts…
Description from the npm listing.
- ai
- ai-sdk
- tools
- cache
- caching
- performance
- llm
- openai
- anthropic
README badge
Show your rank in a README or on your website. The badge updates automatically.
Charts
Images: 30d · 1y · all time · 1600×900 dark
Adoption over time
7/30/90-day growth
Ranking history
Listing placement
Listing placement
Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.
Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.
Recent observations
Full history (170)Similar npm AI SDKs plugins
All 20 @ai-sdk-tools/cache alternativesData source
Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.
Listing: https://www.npmjs.com/package/@ai-sdk-tools/cache. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.