🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

http-cache-semantics

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-cache-semantics

Parses Cache-Control and other headers. Helps building correct HTTP caches and proxies

4.2.0
latest
Version published
Weekly downloads
26M
-7.85%
Maintainers
1
Weekly downloads
 
Created

What is http-cache-semantics?

The http-cache-semantics package is designed to provide a way to interpret HTTP caching headers and make decisions based on them. It helps in implementing HTTP caching compliant with the RFC 7234 standard. The package can be used to parse cache headers, compute cache freshness, and determine the correct caching behavior for requests and responses.

What are http-cache-semantics's main functionalities?

Parsing Cache Headers

This feature allows you to parse the cache-related headers from HTTP requests and responses. It creates a new CachePolicy object that can be used to determine various caching behaviors.

{"const CachePolicy = require('http-cache-semantics');\nconst policy = new CachePolicy(requestHeaders, responseHeaders);\nconst ttl = policy.timeToLive();"}

Computing Cache Freshness

This feature is used to compute whether a cached response is still fresh or if it needs revalidation. It helps in deciding whether to serve the cached response or to make a new request to the origin server.

{"const CachePolicy = require('http-cache-semantics');\nconst policy = new CachePolicy(requestHeaders, responseHeaders);\nconst isFresh = policy.satisfiesWithoutRevalidation(requestHeaders);"}

Updating Cached Responses

This feature is used to update the cache policy object with new response headers, which is useful when a cached response has been revalidated with the origin server.

{"const CachePolicy = require('http-cache-semantics');\nconst policy = new CachePolicy(requestHeaders, responseHeaders);\nconst updatedPolicy = policy.revalidatedPolicy(requestHeaders, newResponseHeaders);"}

Other packages similar to http-cache-semantics

FAQs

Package last updated on 09 May 2025

Did you know?

Socket

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.

Install

Related posts