Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
midd-cache
Advanced tools
Readme
const middCache = require('midd-cache');
app.use(middCache())
After cache expired in the client(browser), client will send a revalidate request with If-Modified-Since
or If-None-Match
headers.
Use req.fresh(status)
to check that, and if cache is fresh, it will response 304 and return true, otherwise it will return false.
The status
is current resource state about Last-Modified
or ETag
.
It could have two keys(keys name is case insensitive):
Last-Modified
or LastModified
: number(ms) or string(utc) or Date. The string format is like date.toUTCString()
ETag
: the etag stringExample:
app.use((req, resp, next)=>{
let lastMod = getRecordLastModified(req.params.id);
if(req.fresh({'Last-Modified': lastMod})) return;
resp.send(updatedRecord)
})
resp.send
This mechanism must be used with midd-send
middleware and only effective on resp.send
method. You should attch midd-send
first.
When you call resp.send(body)
method, it will generate ETag
from the body, and get Last-Modified
from the headers.
Then use them to compare with the request's If-Modified-Since
or If-None-Match
. If the cache is fresh, respond 304, otherwise respond the body with ETag
and Last-Modified
headers.
resp.setCache(options)
Options have:
maxAge
: number, milliseconds. Used in Cache-Control
headerprivate
: boolean. Used in Cache-Control
headerLast-Modified
or LastModified
: number(ms) or string(utc) or Date. The key name is case insensitive.ETag
: the etag string. The key name is case insensitive.Licensed under MIT
Copyright (c) 2017 Tian Jian
FAQs
http cache middleware for midd
The npm package midd-cache receives a total of 10 weekly downloads. As such, midd-cache popularity was classified as not popular.
We found that midd-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.