Registry / devops / metro-cache

metro-cache

JSON →
library0.84.4jsnpmunverified

Metro is the JavaScript bundler for React Native applications. The metro-cache package provides caching layers for Metro, enabling faster builds by storing and retrieving previously computed results. Version 0.84.4 is the current stable release. It is updated frequently alongside Metro releases. Key differentiators include multiple cache backends (file, HTTP, etc.) and integration with Metro's build pipeline. It is part of the official Metro monorepo maintained by Meta.

npm install metro-cache
INSTALL
IMPORT
SIG · METRO-CACHE
M
metro-cache
devopsjavascriptv0.84.4
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.

CacheStore
import { CacheStore } from 'metro-cache'
const CacheStore = require('metro-cache').CacheStore
ESM-only in recent versions; CommonJS require is not recommended but may still work.
FileStore
import { FileStore } from 'metro-cache'
Default export is not available; always use named import.
HttpStore
import { HttpStore } from 'metro-cache'
import HttpStore from 'metro-cache'
HttpStore is a named export, not the default export.

Shows how to create a FileStore and use CacheStore to set and get cached values.

import { FileStore, CacheStore } from 'metro-cache'; const store = new FileStore({ root: '/tmp/cache' }); const cache = new CacheStore(store); async function example() { const key = 'some-key'; const value = { data: 'cached content' }; await cache.set(key, value); const retrieved = await cache.get(key); console.log(retrieved); } example().catch(console.error);
Debug
Known issues
breakingIn version 0.80+, CacheStore API changed: set/get methods now return promises instead of being synchronous.
fix
Ensure you use await or .then() when calling set and get.
affects: >=0.80.0
gotchaFileStore requires a writable directory. Default root may not exist in some environments (e.g., serverless).
fix
Always provide an explicit root directory that exists and is writable.
affects: all
deprecatedHttpStore is deprecated in favor of using a custom store with HTTP backend; may be removed in future versions.
fix
Consider implementing a custom store using the CacheStore interface or use FileStore with a shared filesystem.
affects: >=0.84.0
gotchaCache keys must be strings or Buffers; other types will be coerced and may cause collisions.
fix
Always use string keys, preferably hashed or serialized.
affects: all
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, mkdir '/some/path'
The root directory for FileStore does not exist.
fix
Create the directory before initializing FileStore or set root to an existing directory.
TypeError: cache.set is not a function
Using a synchronous call on an async method without awaiting.
fix
Call cache.set with await or handle the promise.
Error: Invalid cache key type. Expected string or Buffer.
Non-string/non-Buffer key passed to set or get.
fix
Convert key to string, e.g., JSON.stringify or toString().
Upgrade
Version history
0.84.4latest on npm
Audit
Dependencies
metro-corerequiredCore Metro types and utilities
Agent activity
2 hits · last 30 days
node
2
Resources
metro-cache — npm install metro-cache · libregistry