Gathering detailed insights and metrics for popsicle-cache
Gathering detailed insights and metrics for popsicle-cache
Gathering detailed insights and metrics for popsicle-cache
Gathering detailed insights and metrics for popsicle-cache
npm install popsicle-cache
Typescript
Module System
Node Version
NPM Version
71.9
Supply Chain
99.4
Quality
74.6
Maintenance
50
Vulnerability
85
License
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
4 Stars
50 Commits
1 Watchers
24 Branches
2 Contributors
Updated on Dec 12, 2023
Latest Version
5.0.1
Package Id
popsicle-cache@5.0.1
Size
16.00 kB
NPM Version
4.0.3
Node Version
6.9.1
Published on
Dec 19, 2016
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Cache HTTP responses using
popsicle
.
1npm install popsicle-cache --save
1import { request } from 'popsicle' 2import { plugin, cacheables, ttls } from 'popsicle-cache' 3 4const cache = plugin({ engine: require('catbox-fs'), ttl: ttls.forever() }) 5 6popsicle('http://example.com') 7 .use(cache.handle) 8 .then(function (res) { 9 console.log(res) //=> If still fresh, the cached response, otherwise it makes a new request. 10 })
Use popsicleCache.plugin(options)
to initialize the cache middleware. It returns an object with three methods:
handle
- Regular Popsicle middleware for handling the cache.forceUpdate
- Force a refresh of the cache on every request (does not read from cache, only sets it).stop
- Stop the underlying catbox
engine.Popsicle Cache does not include any external caching strategy by default. Instead, it is compatible with catbox
strategies.
engine
(Object | Function)An engine instance from catbox
.
cacheable
(Function, Default = cacheables.standard()
)1(req: Request, res: Response) => boolean
A function that determines whether a request/response should be cacheable.
Built-in cacheable implementations:
cacheables.standard()
- Caches on res.status === 200 && req.method === 'GET' && !res.get('Cache-Control').contains('no-cache')
only.cacheables.always()
- Always caches the response (return true
).ttl
(Function, Default = ttls.standard(0, 1000 * 60 * 60 * 24 * 365)
)1(req: Request, res: Response) => number
A function that determines the TTL of the cached response.
Built-in TTL implementations:
ttls.standard(minTtl, maxTtl)
- Calculates the freshness from the Cache-Control
, Expires
and/or Last-Modified
headers. Returns minTtl + Math.min(maxTtl, freshness)
.ttls.forever()
- Caches forever (return Infinity
).serializer
(Object, Default = serializers.standard()
)1interface Serializer <T> { 2 name: string 3 parse (value: string): T 4 stringify (value: T, cache: (err: Error | null, value?: string | null) => void): T 5}
An object that represents a serializer instance. Must have a name and implement parse
and stringify
methods. Some serializations are asynchronous in nature, or require the response body to be augmented, so a callback must be used to cache the actual value. Pass null
or undefined
as the cache
value to skip the cache (E.g. cache()
or cache(null, null)
).
Built-in serializer implementations:
serializers.standard()
- Simple implementation using JSON.parse
and JSON.stringify
.stream(maxBufferLength?: number)
- Buffers the response body from a stream, skipping the cache if the buffer exceeds maxBufferLength
(defaults to 1mb
)handler
(Function, Default = handlers.standard()
)1class CachedResponse extends popsicle.Response { 2 ttl: number 3 stored: number 4 response: Response 5 varyHeaders: Array<[string, string]> 6} 7 8(req: Request, cache: CachedResponse, next: () => Promise<Response>): Response | CachedResponse | Promise<Response | CachedResponse>
The request handler that decides whether to use the existing cache, regular response or a combination of both (E.g. by setting If-None-Match
or If-Modified-Since
).
Built-in handler implmentations:
handlers.standard()
- Based on freshness, it will decide whether to use the cache directly or validate the cache by sending the request with If-None-Match
or If-Modified-Since
. If it responds with 304
(not modified), it will use the cached response body and headers.handlers.always()
- Always return the cached resource, even if expired or stale (return cache.response
).catchCacheError
(Function, Default = undefined
)1(err: Error) => void
Handler for catching cache errors. Useful for debugging errors with setting the cache engine or serializer errors which would otherwise be swallowed.
staleFallback
(Boolean, Default = true
)When the network is down or the server responds with 5xx
, we always default to the cached entry (instead of passing the error onward).
getId
(Function, Default = getIds.standard()
)The ID for the cache entry. The default is ${serializer.name}~${req.method}~${req.url}
.
waitForCache
(Boolean, Default = false
)Usually persisting to cache occurs in parallel with the response. This overrides that behaviour by waiting for the cache to finish before responding.
segment
(String, Default = 'popsicle-cache'
)The catbox
segment name.
MIT license
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
security policy file detected
Details
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 5/27 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More