Caching
The SDK supports pluggable cache and deduplication stores via @http-client-toolkit. Without stores configured, every request goes directly to the API.
Cache Stores
Section titled “Cache Stores”In-Memory Cache
Section titled “In-Memory Cache”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 },});SQLite Cache (Persistent)
Section titled “SQLite Cache (Persistent)”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' }), },});How Caching Works
Section titled “How Caching Works”Cached responses are returned immediately without making an API call:
const issue1 = await client.issue.retrieve(1); // API callconst issue2 = await client.issue.retrieve(1); // Cache hit - instant returnDeduplication
Section titled “Deduplication”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 callconst [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]);Combining Cache and Deduplication
Section titled “Combining Cache and Deduplication”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 },});Store Comparison
Section titled “Store Comparison”| Feature | In-Memory | SQLite |
|---|---|---|
| Performance | Fastest | Fast |
| Persistence | No (lost on restart) | Yes |
| Cross-process | No | Yes |
| Setup | Zero | Requires file system |
| Best for | Development, single-instance | Production, multi-instance |