@gibme/cache
    Preparing search index...

    @gibme/cache

    @gibme/cache

    A caching helper that provides a unified interface across multiple cache backends.

    • Common async API across all backends (set, get, del, mset, mget, mdel, take, keys, list, clear, ttl)
    • Configurable TTL with automatic expiration
    • Generic key/value types with JSON serialization
    • EventEmitter support for cache events
    • Backend systems supported:
    • Node.js >= 22
    npm install @gibme/cache
    

    https://gibme-npm.github.io/cache

    import Memory from '@gibme/cache/memory';

    const client = new Memory({ stdTTL: 600 });

    await client.set('somekey', { some: 'value' });

    const value = await client.get('somekey');

    if (value) {
    console.log(value);
    }

    await client.disconnect();

    Redis configuration can be supplied directly or via environment variables (REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD).

    import Redis from '@gibme/cache/redis';

    const client = new Redis({
    host: 'localhost',
    username: 'someuser',
    password: 'somepassword'
    });

    await client.set('somekey', { some: 'value' });

    const value = await client.get('somekey');

    if (value) {
    console.log(value);
    }

    await client.disconnect();
    import Database from '@gibme/cache/database';

    const client = new Database({
    stdTTL: 600,
    tableName: 'cache'
    });

    await client.connect();

    await client.set('somekey', { some: 'value' });

    const value = await client.get('somekey');

    if (value) {
    console.log(value);
    }

    await client.disconnect();

    All backends implement the same abstract Cache interface:

    Method Description
    set(key, value, ttl?) Store a value with optional TTL (seconds)
    get(key) Retrieve a value
    del(key) Delete a key
    includes(key) Check if a key exists
    take(key) Get a value and delete it in one operation
    mset(keys, values, ttl?) Set multiple key/value pairs
    mget(keys) Get multiple values
    mdel(keys) Delete multiple keys
    keys() List all keys
    list() Get all entries as a Map
    clear() Delete all entries
    ttl(key, ttl) Update a key's TTL
    getTtl(key) Get remaining TTL in seconds
    connect() Establish backend connection
    disconnect() Close backend connection
    isReady Whether the backend is connected

    MIT