createStorage() is optional. Defaults are tuned for in-memory caching with periodic expiry scans.
Options reference
string
default:"prefix or @brushy:"
Unique instance id. Instances with the same
id share a single in-process object and sync invalidation via the registry bus.string
default:"@brushy:"
Prepended to keys in the persist layer. Does not affect in-memory key names.
number | string
default:"0"
Default TTL in seconds for
set() when no per-key TTL is given. 0 = unlimited. Bare numeric strings use milliseconds for stdTTL (node-cache compatible). See TTL.number
default:"600"
Interval in seconds to scan for expired keys. Set to
0 to disable the background timer.boolean
default:"false"
When
true, values are deep-cloned on get/set via structuredClone (falls back to JSON.parse/stringify).boolean
default:"true"
When
true, expired keys are removed and expired + del events fire. When false, the value remains with expiry cleared.number
default:"-1"
Maximum in-memory keys.
-1 = unlimited. Throws StorageError (MaxKeys) when exceeded.false | 'local' | 'session' | SyncPersist
default:"false"
Write-through persistence. See Persist adapters.
CacheBus
Custom invalidation bus merged with built-in registry and
BroadcastChannel buses. See Cache bus.boolean
default:"false"
LZ-string compress persist payloads larger than 1 KB.
(error: StorageError) => void
Handler for persist quota, serialization, and max-keys errors.
Singleton instances
createStorage({ id: "app" }) returns the same object on subsequent calls with the same id. Use distinct ids when you need isolated caches (e.g. feature-specific namespaces).
SetOptions (per-key)
Passed as the third argument toset() or via useStorage options:
number | string
Per-key TTL. Bare numeric strings are interpreted as seconds.
boolean
Override instance-level
compress for this write.