soundcloud-api-ts - v1.13.4
    Preparing search index...

    Interface SoundCloudCache

    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.

    // Simple in-memory implementation
    class 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);
    }
    }
    interface SoundCloudCache {
        delete(key: string): void | Promise<void>;
        get<T>(key: string): T | Promise<T | undefined> | undefined;
        set<T>(
            key: string,
            value: T,
            options: { ttlMs: number },
        ): void | Promise<void>;
    }
    Index

    Methods

    Methods

    • Remove a cached entry

      Parameters

      • key: string

      Returns void | Promise<void>

    • Retrieve a cached value by key, or undefined if missing or expired

      Type Parameters

      • T

      Parameters

      • key: string

      Returns T | Promise<T | undefined> | undefined

    • Store a value with a TTL in milliseconds

      Type Parameters

      • T

      Parameters

      • key: string
      • value: T
      • options: { ttlMs: number }

      Returns void | Promise<void>