Skip to content

Releases: grischaerbe/cacheables

v3.0.1

29 Apr 22:55
d6be5f0

Choose a tag to compare

What's Changed

Full Changelog: v3.0.0...v3.0.1

v3.0.0

29 Apr 22:05
23295a0

Choose a tag to compare

cacheables v3.0.0

v3 is a ground-up rewrite. The core idea is unchanged — wrap an async call, get caching for free — but the storage model, options shape, and method names are new.

What's new

  • Multilayer storage via buckets. Stack a fast in-memory L1 with any L2/L3 you write (filesystem, Redis, S3, IndexedDB, …). Reads cascade L1 → Ln; on any hit, missing upper layers are back-filled. Writes fan out to every bucket in parallel.
  • Bucket views (cache.resolve). Cacheable<TView> is generic; buckets can publish a domain-specific projection — a local file URL, a presigned S3 link, an ObjectURL — separately from the cached value. cache.resolve() returns the L1 view and shares the policy + dedup pipeline with remember(), so callers stay on a freshness-aware path instead of bypassing the policy with a raw bucket read.
  • Pluggable logger. ILogger interface plus a consoleLogger singleton replaces the boolean log / logTiming flags. One formatted line per call: Cacheable "<namespace>:<key>": HIT|MISS <Xms>. Omit logger for silent operation; assign cache.logger at runtime to flip on/off.
  • Concurrency-safe dedup. Concurrent same-key callers share one cascade probe, one value read, and (for SWR) one background revalidation. Concurrent remember + resolve on the same key still trigger only one producer call.

Migrating from v2

// v2
import { Cacheables } from 'cacheables'

const cache = new Cacheables({ log: true, logTiming: true })

await cache.cacheable(() => fetch(url), 'weather', {
  cachePolicy: 'max-age',
  maxAge: 5_000,
})
// v3
import { Cacheable, MemoryBucket, consoleLogger } from 'cacheables'

const cache = new Cacheable('weather', {
  buckets: [new MemoryBucket()],
  policy: 'max-age',
  maxAge: 5_000,
  logger: consoleLogger,
})

await cache.remember(() => fetch(url).then((r) => r.json()), 'weather')

Breaking changes

  • Class renamed CacheablesCacheable.
  • Method renamed cache.cacheable(...)cache.remember(...).
  • Cache policy moved to the constructor. No per-call options. Pass policy (and maxAge where required) once on new Cacheable(namespace, { ... }). Field is policy, not cachePolicy. A single instance serves a single policy — split into multiple instances to mix.
  • buckets is required. new Cacheable('app', { buckets: [new MemoryBucket()] }) reproduces the v2 default.
  • namespace is required and positional (first constructor argument). Prefixed onto every bucket key as ${namespace}:.
  • delete and clear are async — they return Promise<void>.
  • log / logTiming replaced by logger. Pass consoleLogger to restore default-on logging.
  • Removed: enabled option (call resource() directly to bypass), keys(), isCached(), Cacheables.key(...) (build keys with template literals or [...].join(':')).
  • Buckets can throw. Any throw from any bucket rejects remember(). v2's in-memory store couldn't fail; this is a new error surface once you wire up a custom bucket.

Runtime

  • Node ≥ 18 required.
  • sideEffects: false so bundlers can tree-shake unused exports.
  • Dual ESM/CJS publish, browser + Node, no dependencies.

v2.0.0

05 Jun 10:06

Choose a tag to compare

What's Changed

  • Fix: handle promise rejection and clear pending promise by @hodlen in #8.
  • Hybrid module: ESM and CommonJS – as moving from a pure CommonJS to a hybrid-distributed library does not come without upgrading headaches, I consider this a breaking change.

New Contributors

  • @hodlen made their first contribution in #8 🎉

Full Changelog: v1.2.2...v2.0.0

v1.2.2

11 Nov 10:40
502476b

Choose a tag to compare

Features 🎉

  • Adds an option maxAge to the cache policy stale-while-revalidate to treat a cache as fresh for a certain amount of time and update in the background is maxAge is reached.

v1.1.2

16 Oct 10:46

Choose a tag to compare

README

  • No e-notation in large numbers in README and JSDocs

v1.1.1

15 Oct 11:54

Choose a tag to compare

  • Modified the README to not include top-level await.
  • Added size-limit to devDeps

Full Changelog: v1.1.0...v1.1.1

v1.1.0

15 Oct 11:21

Choose a tag to compare

Features 🎉

  • Support for different cache policies – the former approach was implicitly cache-only or max-age.

Under the hood

  • Major refactoring.
  • More tests.

Breaking changes 🙀

  • As the cache policies are a new feature the API slightly changed.
  • As the concept of misses became unstable and hard to maintain with different cache policies, I dismissed it. Please update your application if it's is depending on the logs of misses. (hits are still a thing…). It might get a new chance at some point though.

v0.3.2

09 Jul 21:24

Choose a tag to compare

Misc

  • README: Better example (same as quickstart)

v0.3.1

09 Jul 21:15

Choose a tag to compare

Misc

  • Added a codesandbox.io quickstart to the README

v0.3.0

09 Jul 20:16

Choose a tag to compare

Features

  • cache.isCached(key) returns whether a cacheable is present and valid (i.e., did not time out)
  • No more setTimeout, therefore less memory leak potential, no cleanup necessary
  • Tests now also include timing edge cases