Registry / database / clay-resource-cache

clay-resource-cache

JSON →
library2.0.3jsnpmunverified

Cache handler for clay-resources, part of the ClayDB ecosystem. Provides an LRU cache with configurable max size and TTL for caching clay-entity objects. Version 2.0.3 is the current stable release; the package is in maintenance mode with no recent updates. It wraps the popular lru-cache library internally and exposes a simple API: create cache with options, store an entity with a unique ID, and retrieve by ID. Unlike generic caching solutions, it integrates seamlessly with clay-entity and clay-resource patterns, but its utility is limited to that ecosystem. The package requires Node >=8 and has no runtime dependencies beyond clay-entity and lru-cache.

npm install clay-resource-cache
INSTALL
IMPORT
SIG · CLAY-RESOURCE-CACH
C
clay-resource-cache
databasejavascriptv2.0.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const clayResourceCache = require('clay-resource-cache')
import clayResourceCache from 'clay-resource-cache'
The package provides a CommonJS default export. ESM import works in Node >=13 with named fallback, but is not officially supported.
create
const { create } = require('clay-resource-cache')
The create function is also exported as a named export. Can be destructured from CommonJS require.
ClayResourceCache
const { ClayResourceCache } = require('clay-resource-cache')
const ClayResourceCache = require('clay-resource-cache').ClayResourceCache
The class is exported as a named export. Typo-safe destructuring is preferred.

Creates a resource cache with max 1000 items and 1-hour TTL, stores and retrieves a clay-entity.

'use strict' const clayResourceCache = require('clay-resource-cache') const clayEntity = require('clay-entity') const cache = clayResourceCache({ max: 1000, maxAge: 1000 * 60 * 60 // 1 hour }) const entity01 = clayEntity({ name: 'The entity 01' }) cache.store(entity01) const cached = cache.get(entity01.id) console.log('Cached entity:', cached) // Cached entity: { id: '...', name: 'The entity 01' }
Debug
Known issues
deprecatedPackage is in maintenance mode with no active development; may not receive updates for Node.js compatibility or security patches.
fix
Consider using a general-purpose caching library like lru-cache directly or migrate to a more actively maintained ClayDB component.
affects: >=2.0.0
breakingVersion 2.0.0 changed the API from a constructor to a factory function; new requires calling as a function instead of 'new'.
fix
Use clayResourceCache(options) instead of new clayResourceCache(options).
affects: >=2.0.0 <3.0.0
gotchaDependency on clay-entity; cache.store() expects an entity with an 'id' property. Storing plain objects without 'id' will cause get() to return undefined.
fix
Always wrap data in clayEntity({...}) before storing, or ensure objects have an 'id' property.
affects: >=1.0.0
deprecatedInternal dependency on lru-cache v4 (legacy version); may have known vulnerabilities or incompatibilities with newer Node.js releases.
fix
Pin Node.js to version 12 or 14, or override lru-cache version in package.json resolutions if possible.
affects: >=2.0.0
gotchaThe cache does not support async/await or Promise-based operations; all methods are synchronous. Using in an async context may block the event loop.
fix
Consider using an async-capable caching library if concurrency is needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: clayResourceCache is not a constructor
Trying to use 'new' with the factory function in v2.
fix
Remove 'new': const cache = clayResourceCache(options) instead of const cache = new clayResourceCache(options).
Cannot find module 'clay-entity'
Missing peer dependency clay-entity.
fix
Run: npm install clay-entity
TypeError: Cannot read property 'id' of undefined
Storing an object without an 'id' property, or calling cache.get() with an undefined key.
fix
Ensure you pass a valid clay-entity object to cache.store(), and that all entities have an 'id' property.
Upgrade
Version history
2.0.3latest on npm
Audit
Dependencies
clay-entityrequiredRequired for creating entity objects to store in cache
lru-cacherequiredUnderlying caching mechanism, used internally by clay-resource-cache
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources