Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse cache entry to single key #67

Merged
merged 4 commits into from
Mar 28, 2023
Merged

Collapse cache entry to single key #67

merged 4 commits into from
Mar 28, 2023

Conversation

colinbendell
Copy link

@colinbendell colinbendell commented Mar 26, 2023

Previously a cache miss would be cached twice - an unversioned entry + a versioned entry for the same cache key. This would allow cases where the versioned entry was not strictly needed and shouldn't cause a cache miss (eg: bot traffic). However, this doubling of the cache entries reduces the effective memory footprint and requires multiple round trips to the backing cache.

This PR collapses the cache to a single key and uses the entity-tag (etag) value for the situations when a strict cache value needs to be evaluated. This reduces the number of queries to the cache while preserving the intended semantics of the cache.

Additionally, we move the a limited header set into the cache. Header caching is required for response metadata caching and will support other use cases such as the use of cache-tags and other cache-control header values.

Other changes in this pr:

  • refactoring the nominclature (cache_key --> is for the lookup, entity_tag is for the version)
  • removed the non-standard header x-alternate-cache-key
  • update gemfile dependency versions

Future work should include:

  • moving from x-cache header to the standard cache-status header
  • removing the UA match for IE <8 's inconsistency with XML-HTTP-Request

@colinbendell colinbendell requested a review from a team as a code owner March 26, 2023 17:57
* uses single cache key
* stores the headers in the cache to make the etag available
* validates against the etag for strict cache hit
* soft etag matches based on TTL for a stale-while-revalidate
lib/response_bank/middleware.rb Show resolved Hide resolved
lib/response_bank/response_cache_handler.rb Outdated Show resolved Hide resolved
lib/response_bank/response_cache_handler.rb Outdated Show resolved Hide resolved
lib/response_bank/response_cache_handler.rb Outdated Show resolved Hide resolved
Co-authored-by: Rafael Mendonça França <[email protected]>
lib/response_bank.rb Outdated Show resolved Hide resolved
lib/response_bank.rb Outdated Show resolved Hide resolved
@colinbendell colinbendell merged commit 33483a8 into main Mar 28, 2023
@colinbendell colinbendell deleted the single_cache_key branch March 28, 2023 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants