
Security News
CISA’s 2025 SBOM Guidance Adds Hashes, Licenses, Tool Metadata, and Context
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
CacheRules is a well-behaved HTTP caching library aimed at being RFC 7234 compliant.
This library does not actually cache anything, and it is not a proxy. It validates HTTP headers and returns the appropriate response to determine if a request can be served from the cache.
It is up to the HTTP Cache implementation to store the cached results and serve responses from the cache if necessary.
Add this line to your Gemfile: gem 'cache_rules'
or
Install with: gem install cache_rules
There is only 1 public API call when using this library: validate()
.
require 'cache_rules'
url = 'https://status.rubygems.org'
request = {'Version' => 'HTTP/1.1'}
cached = {}
CacheRules.validate url, request, cached
=> {:body=>nil, :code=>307, :headers=>{"Cache-Lookup"=>"MISS", "Location"=>"https://status.rubygems.org"}}
The request
headers must be a Ruby Hash or Array of 2-element Arrays.
The cached
headers must already have been normalized by this caching library.
There are two decision tables to help figure out how to process each type of HTTP Caching request.
This HTTP Caching library aims to be RFC 7230-7235 compliant. It is a best effort attempt to correctly interpret these documents. Some errors may exist, so please notify me if something isn't processed correctly according to the RFCs.
Last-Modified
)Fri, 31 Dec 1999 23:59:59 GMT
)Pragma: no-cache
)If-None-Match: "W/abc123"
)If-Modified-Since: Thu, 01 Jan 2015 07:03:45 GMT
)no-cache="Cookie"
)Authorization
)Custom headers are generated to help with testing and compliance validation.
These are somewhat based on CloudFlare's cache headers:
Cache-Lookup: HIT
: resource is in cache and still valid. Serving from the cache.Cache-Lookup: MISS
: resource is not in cache. Redirecting to the origin server.Cache-Lookup: EXPIRED
: resource is in cache, but expired. Redirecting to the origin server or serving an error message.Cache-Lookup: STALE
: resource is in cache and expired, but the origin server wasn't contacted successfully to revalidate the request. Serving stale response from the cache.Cache-Lookup: REVALIDATED
: resource is in cache, was expired, but was revalidated successfully at the origin server. Serving from the cache.To run the tests, type:
bundle exec rake test
s-maxage
response headerVary
header and different representations for the same resource206 (Partial)
and Range
headers for resuming downloadsCache-Control: private
headersC.R.E.A.M. is an influencial lyrical masterpiece from the 90s performed by the Wu-Tang Clan
It's also the premise of this troll video
Some useful articles explaining HTTP Caching:
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) 2014-2015 Alexander Williams, Unscramble
FAQs
Unknown package
We found that cache_rules demonstrated a not healthy version release cadence and project activity because the last version was released 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
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.