Registry / storage / miniprogram-network-cache

miniprogram-network-cache

JSON →
library5.3.0-alpha.0jsnpmunverified

A cache library for WeChat Mini Programs (微信小程序) that wraps network requests with deduplication and caching. Version 5.3.0-alpha.0, pre-release with active development. Provides CacheOperator to merge concurrent identical requests and cache responses based on configurable key builder and expiry. Differentiator: specifically designed for WeChat Mini Program API (wx.request) with zero-config defaults for common use cases, unlike generic browser caches.

npm install miniprogram-network-cache
INSTALL
IMPORT
SIG · MINIPROGRAM-NETWOR
M
miniprogram-network-cache
storagejavascriptv5.3.0-alpha.0
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.

CacheOperator
import { CacheOperator } from 'miniprogram-network-cache'
const CacheOperator = require('miniprogram-network-cache')
ESM only; CJS require not supported.
defaultKeyBuilder
import { defaultKeyBuilder } from 'miniprogram-network-cache'
import defaultKeyBuilder from 'miniprogram-network-cache'
Named export, not default.
isOkResult
import { isOkResult } from 'miniprogram-network-cache'
import { isOkResult } from 'miniprogram-network'
Exported from this package, not the parent miniprogram-network.

Creates a cached wx.request handler that caches responses for 60 seconds and deduplicates identical requests.

import { CacheOperator } from 'miniprogram-network-cache'; const cachedRequest = CacheOperator.createHandler(wx.request, { expire: 60000, // 60 seconds resultCondition: (res) => res.statusCode === 200, keyBuilder: (opts) => opts.url }); // First request sends actual network call cachedRequest({ url: 'https://api.example.com/data' }).then(res => console.log(res)); // Second identical request within 60s returns cached result, no network call cachedRequest({ url: 'https://api.example.com/data' }).then(res => console.log(res));
Debug
Known issues
breakingPackage is alpha pre-release; API may change without notice.
fix
Pin to exact version and test thoroughly before upgrading.
affects: >=5.3.0-alpha.0
gotchaDefault keyBuilder uses JSON.stringify(opts) which may cause large cache keys and hit memory limits.
fix
Provide a custom keyBuilder that generates a short unique string (e.g., op.url + JSON.stringify(op.data)).
affects: >=0.0.0
gotchaCache is in-memory only; does not persist across mini program restarts.
fix
Implement persistent storage (e.g., wx.setStorage) separately if needed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'miniprogram-network-cache'
Package not installed or npm install failed.
fix
Run 'npm install miniprogram-network-cache@5.3.0-alpha.0' and ensure package.json includes it.
Uncaught TypeError: CacheOperator is not a constructor
Using 'new CacheOperator' incorrectly; CacheOperator is a class but createHandler is a static method.
fix
Use 'CacheOperator.createHandler(...)' or 'const operator = new CacheOperator(...)' then call operator.createHandler() – but recommended to use createHandler directly.
Upgrade
Version history
5.3.0-alpha.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
18
Resources
miniprogram-network-cache — npm install miniprogram-network-cache · libregistry