Registry / storage / array-buffer-cache

array-buffer-cache

JSON →
library4.0.121jsnpmunverified

Asynchronous cache for ArrayBuffers with TypeScript support. Current stable version is 4.0.121. Provides a simple, non-blocking interface for caching binary data. Alternates like lru-cache or node-cache are synchronous and not optimized for ArrayBuffers. This package is dependency-free and ships bundled TypeScript definitions.

npm install array-buffer-cache
INSTALL
IMPORT
SIG · ARRAY-BUFFER-CACHE
A
array-buffer-cache
storagejavascriptv4.0.121
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.

ArrayBufferCache
import { ArrayBufferCache } from 'array-buffer-cache'
const ArrayBufferCache = require('array-buffer-cache')
Default export is not available; always use named import. TypeScript declarations included.
ArrayBufferCache
import type { ArrayBufferCache } from 'array-buffer-cache'
import { ArrayBufferCache } from 'array-buffer-cache'
Use type import for type-only usage to avoid runtime overhead.
ArrayBufferCacheOptions
import type { ArrayBufferCacheOptions } from 'array-buffer-cache'
import { ArrayBufferCacheOptions } from 'array-buffer-cache'
Options interface is only a type, not a runtime value.

Creates a cache instance with a 1GB limit, stores and retrieves an ArrayBuffer asynchronously.

import { ArrayBufferCache } from 'array-buffer-cache'; const cache = new ArrayBufferCache({ maxSize: 1000 * 1024 * 1024 }); // 1GB max async function example() { const key = 'myBuffer'; const buffer = new ArrayBuffer(1024); await cache.set(key, buffer); const cached = await cache.get(key); console.log(cached.byteLength); // 1024 } example();
Debug
Known issues
gotchaThe cache does not clone the buffer on retrieval; mutations by the caller affect the cached buffer directly.
fix
Copy the buffer manually if needed: const copy = buffer.slice(0);
affects: >=4.0.0
deprecatedThe 'maxAge' option was removed in v4. Use a custom eviction strategy instead.
fix
Implement periodic cleanup using setInterval if time-based expiry is required.
affects: >=4.0.0
breakingIn v4, the constructor now expects an options object (previously no arguments).
fix
Update new ArrayBufferCache() to new ArrayBufferCache({}) or provide options.
affects: >=4.0.0
gotchaThe 'get' method returns a reference to the stored buffer, not a copy. Mutations to the returned ArrayBuffer affect the cache entry.
fix
Clone after retrieval if mutation is expected.
affects: >=4.0.0
deprecatedThe 'size' property (number of entries) is deprecated; use 'stats()' instead.
fix
Use cache.stats().entryCount
affects: >=4.0.0
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Importing the package incorrectly (e.g., default import instead of named import).
fix
Use named import: import { ArrayBufferCache } from 'array-buffer-cache'
Cannot find module 'array-buffer-cache'
Package not installed or typo in the module name.
fix
Run npm install array-buffer-cache
Property 'byteLength' does not exist on type 'ArrayBuffer | undefined'
TypeScript strict mode without null check on get() result.
fix
Check for undefined before accessing properties: const cached = await cache.get(key); if (cached) { console.log(cached.byteLength); }
ERR_INVALID_ARG_TYPE: The "value" argument must be an instance of ArrayBuffer
Passing non-ArrayBuffer value to set().
fix
Ensure the value is an ArrayBuffer: cache.set(key, new ArrayBuffer(data.byteLength))
Upgrade
Version history
4.0.121latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
30
Resources
array-buffer-cache — npm install array-buffer-cache · libregistry