Socket
Book a DemoInstallSign in
Socket

@furystack/cache

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@furystack/cache

Cache providers for FuryStack package

latest
Source
npmnpm
Version
5.0.22
Version published
Maintainers
1
Created
Source

@furystack/cache

A simple caching utility for FuryStack, providing in-memory cache management to improve performance and reduce redundant computations in your applications.

Usage Examples

Basic In-Memory Cache

import { Cache } from '@furystack/cache'

const cache = new Cache({ load: (a: number, b: number) => Promise.resolve(a + b) })

const result = await cache.get(1, 2) // 3 will be calculated and cached
const cachedResult = await cache.get(1, 2) // Returns cached value: 3

Expiration

import { Cache } from '@furystack/cache'
const cache = new Cache({
  load: (a: number, b: number) => Promise.resolve(a + b),
  expirationMs: 5000, // Cache expires after 5 seconds
})
const result = await cache.get(1, 2) // 3 will be calculated and cached
setTimeout(async () => {
  const expiredResult = await cache.get(1, 2) // Cache expired, recalculates: 3
}, 6000)

Limit capacity

import { Cache } from '@furystack/cache'
const cache = new Cache({
  load: (a: number, b: number) => Promise.resolve(a + b),
  capacity: 2, // Limit cache to 2 items
})
await cache.get(1, 2) // 3 will be calculated and cached
await cache.get(2, 3) // 5 will be calculated and cached
await cache.get(3, 4) // 7 will be calculated and cached, evicts (1, 2) from cache
const result = await cache.get(1, 2) // Recalculates: 3

Invalidate

import { Cache } from '@furystack/cache'
const cache = new Cache({
  load: (a: number, b: number) => Promise.resolve(a + b),
})
await cache.get(1, 2) // 3 will be calculated and cached
cache.remove(1, 2) // Removes the specific cached item
const result = await cache.get(1, 2) // Recalculates: 3

// Remove specific range, where the sum is 3 or the arguments are as specified
cache.removeRange((entity, args) => {
  return entity === 3 || (args[0] === 1 && args[1] === 3)
})

cache.flushAll() // Removes all cached items

Subscribe to changes

import { Cache } from '@furystack/cache'
const cache = new Cache({
  load: (a: number, b: number) => Promise.resolve(a + b),
  expirationMs: 5000, // Cache expires after 5 seconds
})

const observable = cache.getObservable(1, 2)

observable.subscribe(({ status, value }) => {
  console.log(`Cache status: ${status}, Value: ${value}`)
})

Keywords

FuryStack

FAQs

Package last updated on 17 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts