Skip to content

Caching

The SDK supports pluggable cache and deduplication stores via @http-client-toolkit. Without stores configured, every request goes directly to the API.

Best for development, testing, and single-instance applications:

import ComicVine from 'comic-vine-sdk';
import { InMemoryCacheStore } from '@http-client-toolkit/store-memory';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
cache: new InMemoryCacheStore({
maxItems: 5000,
cleanupIntervalMs: 120000, // Cleanup every 2 minutes
}),
},
client: {
defaultCacheTTL: 600, // 10 minutes
},
});

Recommended for production. Data survives application restarts:

import ComicVine from 'comic-vine-sdk';
import { SQLiteCacheStore } from '@http-client-toolkit/store-sqlite';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
cache: new SQLiteCacheStore({ database: './comic-vine-cache.db' }),
},
});

Cached responses are returned immediately without making an API call:

const issue1 = await client.issue.retrieve(1); // API call
const issue2 = await client.issue.retrieve(1); // Cache hit - instant return

Deduplication prevents concurrent identical requests from hitting the API multiple times. When multiple calls request the same resource simultaneously, only one HTTP request is made:

import { InMemoryDedupeStore } from '@http-client-toolkit/store-memory';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
dedupe: new InMemoryDedupeStore({
jobTimeoutMs: 300000, // 5 minutes
}),
},
});
// All three requests share a single HTTP call
const [a, b, c] = await Promise.all([
client.issue.retrieve(1), // Makes API call
client.issue.retrieve(1), // Waits for first call
client.issue.retrieve(1), // Waits for first call
]);

Use both stores together for maximum optimization:

import {
InMemoryCacheStore,
InMemoryDedupeStore,
} from '@http-client-toolkit/store-memory';
const client = new ComicVine({
apiKey: 'your-api-key',
stores: {
cache: new InMemoryCacheStore({ maxItems: 1000 }),
dedupe: new InMemoryDedupeStore({ jobTimeoutMs: 300000 }),
},
client: {
defaultCacheTTL: 300, // 5 minutes
},
});
FeatureIn-MemorySQLite
PerformanceFastestFast
PersistenceNo (lost on restart)Yes
Cross-processNoYes
SetupZeroRequires file system
Best forDevelopment, single-instanceProduction, multi-instance