
Security News
pnpm 11.5 Adds Support for Recognizing npm Staged Publishes
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.
@nimpl/cache-server
Advanced tools
A standalone HTTP server that exposes a `CacheHandler` instance via HTTP API. Designed to work with `FetchLayer` from `@nimpl/cache` to enable distributed caching across multiple application instances.
A standalone HTTP server that exposes a CacheHandler instance via HTTP API. Designed to work with FetchLayer from @nimpl/cache to enable distributed caching across multiple application instances.
npm install @nimpl/cache-server @nimpl/cache
# or
pnpm add @nimpl/cache-server @nimpl/cache
@nimpl/cache-server provides an HTTP server that wraps any CacheHandler instance and exposes it through a standardized HTTP API. This enables you to:
FetchLayer in your applications to access the cache remotelyThe server implements the HTTP API expected by FetchLayer, making it easy to set up distributed caching solutions.
Create a cache handler and start the server:
import { run } from "@nimpl/cache-server";
import { CacheHandler, LruLayer, FsLayer } from "@nimpl/cache";
const cacheHandler = new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new FsLayer(),
});
run(cacheHandler);
The server will start on http://localhost:4000 by default.
import { run } from "@nimpl/cache-server";
import { CacheHandler, LruLayer, RedisLayer } from "@nimpl/cache";
const cacheHandler = new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new RedisLayer(),
});
run(cacheHandler, {
port: 8080,
host: "0.0.0.0",
verifyRequest: async (req) => {
// Add authentication/authorization logic
const authHeader = req.headers.authorization;
return authHeader === `Bearer ${process.env.CACHE_TOKEN}`;
},
});
In your application instances, use FetchLayer to connect to the cache server:
// cache-handler.js
import { CacheHandler, LruLayer, FetchLayer } from "@nimpl/cache";
export default new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new FetchLayer({
baseUrl: process.env.CACHE_SERVER_URL || "http://cache-server:4000",
}),
});
init(cacheHandler, options?)Creates an HTTP server instance without starting it. Useful when you need to control when the server starts or integrate it with other server frameworks.
Parameters:
cacheHandler (CacheHandlerRoot): The cache handler instance to expose via HTTPoptions (CacheServerOptions): Optional configuration
verifyRequest ((req: IncomingMessage) => Promise<boolean>): Optional callback to verify/authenticate requests. Return false to reject the request with 403 status.Returns: http.Server - The HTTP server instance
Example:
import { init } from "@nimpl/cache-server";
import { CacheHandler, LruLayer, RedisLayer } from "@nimpl/cache";
const cacheHandler = new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new RedisLayer(),
});
const server = init(cacheHandler, {
verifyRequest: async (req) => {
// Custom authentication logic
return true;
},
});
// Start the server manually
server.listen(4000, "0.0.0.0", () => {
console.log("Cache server running on port 4000");
});
run(cacheHandler, options?)Creates and starts an HTTP server that exposes the cache handler.
Parameters:
cacheHandler (CacheHandlerRoot): The cache handler instance to expose via HTTPoptions (CacheServerOptions): Optional configuration
port (number): Port to run the server on. Default: 4000host (string): Host to bind the server to. Default: "localhost"verifyRequest ((req: IncomingMessage) => Promise<boolean>): Optional callback to verify/authenticate requests. Return false to reject the request with 403 status.Returns: http.Server - The HTTP server instance
Example:
import { run } from "@nimpl/cache-server";
import { CacheHandler, LruLayer, FsLayer } from "@nimpl/cache";
const cacheHandler = new CacheHandler({
ephemeralLayer: new LruLayer(),
persistentLayer: new FsLayer(),
});
run(cacheHandler, {
port: 4000,
host: "0.0.0.0",
});
The server implements the following HTTP endpoints expected by FetchLayer:
GET /?key=<key>Retrieves a cache entry.
key (required): The cache key200 OK: Returns the cache entry as a stream with x-cache-metadata header404 Not Found: Cache entry not found400 Bad Request: Missing key parameter500 Internal Server Error: Server errorPOST /?key=<key>Stores a cache entry.
key (required): The cache keyx-cache-metadata (required): JSON string containing cache metadata (tags, timestamp, stale, expire, revalidate)Content-Type: application/octet-stream200 OK: Entry stored successfully400 Bad Request: Missing key or metadata500 Internal Server Error: Server errorPUT /?key=<key>Updates cache lifetimes for a single key using the handler’s updateKey method.
key (required): The cache key to updatedurations object (e.g. { "durations": { "expire": 60 } })PUT /Updates tags for cache entries.
tags (array) and optional durations object200 OK: Tags updated successfully400 Bad Request: Invalid request body500 Internal Server Error: Server errorDELETE /?key=<key>Deletes a cache entry.
key (required): The cache key200 OK: Entry deleted successfully400 Bad Request: Missing key parameter500 Internal Server Error: Server errorGET /keysReturns all cache keys.
200 OK: JSON array of cache keys500 Internal Server Error: Server errorGET /readinessHealth check endpoint.
200 OK: JSON object with ready boolean indicating cache handler readinessThe server does not include built-in authentication. For production deployments, you should implement request verification using the verifyRequest option:
run(cacheHandler, {
verifyRequest: async (req) => {
// Example: Verify API token
const authHeader = req.headers.authorization;
const expectedToken = process.env.CACHE_SERVER_TOKEN;
if (!authHeader || !expectedToken) {
return false;
}
return authHeader === `Bearer ${expectedToken}`;
},
});
For additional security, consider:
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
CMD ["node", "server.js"]
The cache server can be deployed as a separate service in Kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: cache-server
spec:
replicas: 1
selector:
matchLabels:
app: cache-server
template:
metadata:
labels:
app: cache-server
spec:
containers:
- name: cache-server
image: your-registry/cache-server:latest
ports:
- containerPort: 4000
env:
- name: REDIS_URL
valueFrom:
secretKeyRef:
name: cache-secrets
key: redis-url
See the external-store-server example for a complete setup demonstrating cache server with filesystem storage.
FAQs
A standalone HTTP server that exposes a `CacheHandler` instance via HTTP API. Designed to work with `FetchLayer` from `@nimpl/cache` to enable distributed caching across multiple application instances.
The npm package @nimpl/cache-server receives a total of 20 weekly downloads. As such, @nimpl/cache-server popularity was classified as not popular.
We found that @nimpl/cache-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
pnpm 11.5 now recognizes npm staged publish approvals in release metadata, preventing those releases from being mistaken for lower-trust package publishes.

Security News
Federal audit finds NIST lacked a plan to clear the NVD backlog, wasted funds on duplicate work, and delayed use of CISA data.

Research
/Security News
A mini Shai-Hulud campaign compromised Red Hat Cloud Services npm packages to steal developer and CI/CD secrets during installation.