Registry / storage / fragment-cache

fragment-cache

JSON →
library0.2.1jsnpmunverified

A cache for managing namespaced sub-caches, version 0.2.1. Last updated in 2017, this package is in maintenance mode with no recent releases. It provides a simple API to create named caches using map-cache internally. Differentiators: lightweight, minimalistic, but obsolete for modern applications with native Map or WeakMap.

npm install fragment-cache
INSTALL
IMPORT
SIG · FRAGMENT-CACHE
F
fragment-cache
storagejavascriptv0.2.1
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.

FragmentCache
const FragmentCache = require('fragment-cache');
const fragmentCache = require('fragment-cache').FragmentCache;
This package uses CommonJS; no ESM exports available.
new FragmentCache()
var fragment = new FragmentCache();
var fragment = FragmentCache.create();
Class instantiation only; no factory method.
set
fragment.set('cacheName', 'key', value);
fragment.set('key', value);
Requires both cache name and key as first two arguments.

Creates a FragmentCache instance, sets and retrieves values from a namespaced sub-cache.

const FragmentCache = require('fragment-cache'); const fragment = new FragmentCache(); // Automatically creates a new sub-cache fragment.set('users', '1', { name: 'Alice' }); console.log(fragment.get('users', '1')); // { name: 'Alice' } // Check existence console.log(fragment.has('users', '1')); // true // Get entire sub-cache console.log(fragment.get('users')); // MapCache { '1' => { name: 'Alice' } }
Debug
Known issues
deprecatedPackage is unmaintained; not recommended for new projects.
fix
Use a modern cache library like node-cache or built-in Map.
affects: >=0.1.0
gotchaset/get/has require the cache name as first argument; omitting it will cause errors.
fix
Always provide 'name' as first argument.
affects: >=0.1.0
gotchaThe entire cache object is returned when get(name) is called without key; modifying it affects the internal cache.
fix
Treat the returned cache as read-only to avoid unintended mutations.
affects: >=0.1.0
Errors
Common errors & fixes
fragment.get('users') returns undefined after set
get(key) without cache name returns the entire cache, but set expects a cache name as first argument.
fix
Use fragment.get('users', 'key') to retrieve a specific value, or fragment.get('users') to get the whole cache.
TypeError: fragment.set is not a function
Forgot to instantiate FragmentCache with 'new'.
fix
Use 'new FragmentCache()' to create an instance.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
map-cacherequiredInternal cache implementation uses map-cache
Agent activity
62 hits · last 30 days
node
60
Amazon
1
Resources
fragment-cache — npm install fragment-cache · libregistry