open-policy-agent/opa

Interquery http.send cache - Add provision to exclude/include headers from cache key

Opened this issue · 3 comments

What is the underlying problem you're trying to solve?

There are usecases where we need to cache responses but the requests have guaranteed unique headers (example: trace-id) that prevent us from using the inter query cache functionality.

Describe the ideal solution

The http.send built in must support a header exclusion list that are not matched when looking up entries from inter query cache. Not sure if it's possible today.

Describe a "Good Enough" solution

Same as the ideal solution described above.

Additional Context

N/A

Currently the entire request object is used as the cache key. It would be interesting to look into how that behavior can be controlled via a new param maybe. So by default the entire object is used as a key and we could specify a list of fields that won't be part of the key generation.

@rudrakhp if you'd like to contribute this feature feel free to do so.

@ashutosh-narkar Although the solution is not ideal, the above PR has changes that suffices our usecase at the moment.
Eg: If there is a change in the exclusion list, a new cache key is generated which leads to a cache miss. A more optimised solution would be to check if the new exclusion list is a subset of the current one and still serve from cache.
Let me know if it looks good to you. Thanks!