Cache interface for SoundCloud API responses.
Implement this interface to plug in any caching backend (in-memory, Redis, etc.). Pass an instance as cache in SoundCloudClientConfig to enable caching.
cache
// Simple in-memory implementationclass SimpleCache implements SoundCloudCache { private store = new Map<string, SoundCloudCacheEntry<unknown>>(); get<T>(key: string): T | undefined { const entry = this.store.get(key) as SoundCloudCacheEntry<T> | undefined; if (!entry || Date.now() > entry.expiresAt) return undefined; return entry.value; } set<T>(key: string, value: T, { ttlMs }: { ttlMs: number }): void { this.store.set(key, { value, expiresAt: Date.now() + ttlMs }); } delete(key: string): void { this.store.delete(key); }} Copy
// Simple in-memory implementationclass SimpleCache implements SoundCloudCache { private store = new Map<string, SoundCloudCacheEntry<unknown>>(); get<T>(key: string): T | undefined { const entry = this.store.get(key) as SoundCloudCacheEntry<T> | undefined; if (!entry || Date.now() > entry.expiresAt) return undefined; return entry.value; } set<T>(key: string, value: T, { ttlMs }: { ttlMs: number }): void { this.store.set(key, { value, expiresAt: Date.now() + ttlMs }); } delete(key: string): void { this.store.delete(key); }}
Remove a cached entry
Retrieve a cached value by key, or undefined if missing or expired
undefined
Store a value with a TTL in milliseconds
Cache interface for SoundCloud API responses.
Implement this interface to plug in any caching backend (in-memory, Redis, etc.). Pass an instance as
cachein SoundCloudClientConfig to enable caching.Example