New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

portacache

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

portacache

Portable key-value cache that auto-selects the best storage backend

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

portacache

Portable key-value cache that auto-selects the best storage backend

Install

npm install portacache

Usage

import createCache from 'portacache';

const cache = createCache({ttl: 5000});

await cache.set('user', {name: 'Alice'});

await cache.get('user');
//=> {name: 'Alice'}

await cache.has('user');
//=> true

await cache.delete('user');
//=> true

await cache.clear();

API

createCache(options?)

Returns a cache instance with get, set, has, delete, and clear methods. All methods are async and return promises.

options

Type: object

backend

Type: 'auto' | 'memory'
Default: 'auto'

The storage backend to use. Currently defaults to an in-memory Map store.

ttl

Type: number

Default TTL in milliseconds for cache entries.

cache.get(key)

Returns the cached value, or undefined if not found or expired.

cache.set(key, value, ttl?)

Store a value in the cache. Optionally pass a per-entry ttl in milliseconds that overrides the default.

cache.has(key)

Returns true if the key exists and has not expired.

cache.delete(key)

Delete a key from the cache. Returns true if the key was deleted.

cache.clear()

Clear all entries from the cache.

  • is-runtime - Detect the current JavaScript runtime environment

License

MIT

Keywords

cache

FAQs

Package last updated on 16 Feb 2026

Related posts