New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

@gibme/cache

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gibme/cache

A caching helper wrapped around various cache types

latest
Source
npmnpm
Version
22.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

@gibme/cache

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

Features

  • 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-cache (in-memory)
    • redis
    • SQL databases via @gibme/sql (MySQL, MariaDB, PostgreSQL, SQLite)

Requirements

  • Node.js >= 22

Installation

npm install @gibme/cache

Documentation

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

Usage

Memory

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

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();

Database

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();

API

All backends implement the same abstract Cache interface:

MethodDescription
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
isReadyWhether the backend is connected

License

MIT

FAQs

Package last updated on 03 Apr 2026

Related posts