Registry / storage / imba-cache

imba-cache

JSON →
library1.1.18jsnpmunverified

A TypeScript-first localStorage caching library (v1.1.18) with support for sessionStorage, memory cache, and cookies. Provides timer-based expiration (seconds/minutes), promise-based and synchronous APIs. Lightweight and zero-dependency, primarily used in Chinese-speaking developer communities. Current version is stable but infrequently updated.

npm install imba-cache
INSTALL
IMPORT
SIG · IMBA-CACHE
I
imba-cache
storagejavascriptv1.1.18
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.

setCache
import { setCache } from 'imba-cache'
const setCache = require('imba-cache').setCache
ESM-only; named import is standard. CommonJS require() works but discouraged.
getCache
import { getCache } from 'imba-cache'
import getCache from 'imba-cache'
Default import is not supported. This function is a named export.
imbaCache
import * as imbaCache from 'imba-cache'
import imbaCache from 'imba-cache'
Namespace import for all functions. Default import does not exist.

Shows basic caching with sessionStorage (default) and localStorage using setCache, getCache, and delCache with expiration.

import { setCache, getCache, delCache } from 'imba-cache'; setCache('token', 'abc123', 5); // expires in 5 minutes const token = getCache('token'); console.log(token); // 'abc123' delCache('token'); console.log(getCache('token')); // null import { setCacheLoca, getCacheLoca } from 'imba-cache'; setCacheLoca('user', { name: 'Alice' }); const user = getCacheLoca('user'); console.log(user); // { name: 'Alice' }
Debug
Known issues
gotchasetCache default time unit is minutes, not seconds. Passing 1 means 1 minute.
fix
Use third argument as minutes or pass a string like 'ss', 'mm', 'hh' as fourth argument.
affects: >=1.0.0
deprecatedsetVariable function is undocumented but exported. It may be removed in future versions.
fix
Avoid using setVariable; use setCache or setCacheLoca instead.
affects: >=1.0.0
gotchasetCache and setCacheLoca store non-string values via JSON.stringify, but retrieval returns the parsed object. Mixing with plain localStorage may cause issues.
fix
Always use library functions for both set and get to ensure proper serialization.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'imba-cache'
Package not installed or incorrect import path
fix
Run 'pnpm add imba-cache' or 'npm install imba-cache'
Uncaught TypeError: setCache is not a function
Using default import instead of named import
fix
Use 'import { setCache } from 'imba-cache'' instead of 'import setCache from 'imba-cache''
TypeError: Cannot read properties of null (reading '0')
Accessing expired cache entry returns null
fix
Check for null before using the result: const val = getCache('key'); if (val) { ... }
Upgrade
Version history
1.1.18latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
24
OpenAI (training)
1
Resources
imba-cache — npm install imba-cache · libregistry