Registry / devops / cache-immutable

cache-immutable

JSON →
library1.0.2jsnpmunverified

A minimalist Node.js library that sets HTTP response headers to cache content for a long time (one year). Version 1.0.2 is the latest stable release, with no active development since 2016. The library sets Cache-Control: max-age=31536000 and omits Expires and Pragma headers, relying on HTTP/1.1 best practices where max-age overrides Expires. It is intended for immutable static assets. Unlike more complex caching libraries, it provides a single function with no configuration, making it ideal for simple use cases.

npm install cache-immutable
INSTALL
IMPORT
SIG · CACHE-IMMUTABLE
C
cache-immutable
devopsjavascriptv1.0.2
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.

default
import cacheImmutable from 'cache-immutable'
const cacheImmutable = require('cache-immutable')
The package supports CommonJS require() but for ESM environments, use default import.
default
const cacheImmutable = require('cache-immutable')
const { cacheImmutable } = require('cache-immutable')
The module exports a single function, not a named export.
default
import cache from 'cache-immutable'
import { cache } from 'cache-immutable'
You can rename the default import, but must not use destructuring.

Creates an HTTP server that sets immutable caching headers on every response.

import http from 'http'; import cacheImmutable from 'cache-immutable'; const server = http.createServer((req, res) => { cacheImmutable(res); res.end('Hello World'); }); server.listen(3000, () => { console.log('Server running on port 3000'); });
Debug
Known issues
gotchaThe function only sets Cache-Control; it does not set Expires or Pragma headers.
fix
If you need HTTP/1.0 compatibility, consider adding Expires header manually.
affects: >=1.0.0
gotchaThe library does not validate that the argument is an http.ServerResponse object; passing invalid input will throw at runtime.
fix
Ensure you pass a proper response object from Node.js http module.
affects: >=1.0.0
deprecatedThe package has not been updated since 2016; it may not support newer Node.js features or ESM natively.
fix
Consider using a more modern caching library or handle headers manually.
affects: >=1.0.0
gotchaCache-Control max-age is set to one year (31536000 seconds), which may be too aggressive for frequently updated content.
fix
Only use for truly immutable assets; otherwise customise max-age.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: cacheImmutable is not a function
Importing as a named export instead of default.
fix
Use `import cacheImmutable from 'cache-immutable'` or `const cacheImmutable = require('cache-immutable')`.
ReferenceError: cacheImmutable is not defined
Forgetting to import the module.
fix
Add the import statement at the top of your file.
TypeError: res.setHeader is not a function
Passing a non-response object to cacheImmutable.
fix
Ensure the argument is a Node.js http.ServerResponse or compatible object.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
cache-immutable — npm install cache-immutable · libregistry