-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Improve http.send cache lookup and freshness logic #5300
Comments
In order to calculate if a cached entry expired or not, we would previously read the headers stored with the request, and parse each of the relevant date-related ones and use those to compare with the current time. open-policy-agent#4960 improved this by allowing us to ignore the Date header completely when force_cache is enabled. We now go one step further, and calculate and store an expiresAt value at the time the entry is created. This allows for a much simpler check of expiry, and avoids re-parsing the header values with each lookup. Fixes open-policy-agent#5300 Signed-off-by: Anders Eknert <anders@eknert.com>
In order to calculate if a cached entry expired or not, we would previously read the headers stored with the request, and parse each of the relevant date-related ones and use those to compare with the current time. #4960 improved this by allowing us to ignore the Date header completely when force_cache is enabled. We now go one step further, and calculate and store an expiresAt value at the time the entry is created. This allows for a much simpler check of expiry, and avoids re-parsing the header values with each lookup. Fixes #5300 Signed-off-by: Anders Eknert <anders@eknert.com>
@anderseknert does this also improve some kind of automatic cache items invalidation when the Thanks! |
Could you open an issue, please? (Or search for an existing one?) It seems like having a periodic cache-cleaning routine would help you, but let's flesh out the details together. |
Sure, I wasn't sure if this improves the situation somehow or not. I'm not too familiar with your codebase yet. |
The idea here was to straighten something out that was a bit quirky in the code. No functional changes involved. Thanks for the issue! |
The current approach to cache lookups and freshness checks is to store the headers as sent by the remote server, and each time we check if an entry should be fetched from cache or from the remote, we parse all the relevant date-related headers —
Date
,Cache-Control
(includingmax-age
) andExpires
in order to determine if the cache entry is fresh.Let's instead do this parsing only once — when the cache entry is created, and store the timestamps directly for comparison in the freshness checks. This would improve performance of cache lookups, but it would also nicely abstract away the details of the HTTP spec from the caching logic.
In order to do this, we'll need to extend the test suite for inter query caching in
http.send
, which surprisingly was almost non-existent before #5298 .. while some e2e tests are added there, we'll probably need another approach to test expiry.The text was updated successfully, but these errors were encountered: