Fix: Ensure Surrogate Keys use TTL from Caddyfile #645
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit modifies the surrogate key storage mechanism to respect the TTL (Time-To-Live) specified in the Caddyfile's
ttl
directive.Previously, surrogate keys were stored with a hardcoded, often indefinite, TTL based on the storage backend (e.g., Redis, Badger). This change propagates the TTL from the main cache configuration down to the surrogate key provider.
Key changes include:
pkg/surrogate/providers/common.go
:baseStorage.init()
now accepts adefaultTTL
parameter.defaultTTL
for surrogate key duration if positive; otherwise, it falls back to the previousstorageToInfiniteTTLMap
.pkg/surrogate/surrogate.go
,pkg/surrogate/providers/factory.go
, andpkg/surrogate/providers/souin.go
to pass thedefaultTTL
through their respective initialization functions.pkg/middleware/middleware.go
:NewHTTPCacheHandler
now retrieves thedefaultTTL
from the configuration and passes it tosurrogate.InitializeSurrogate
.pkg/surrogate/providers/common_test.go
:Set
.This resolves the issue where surrogate keys did not expire according to the configured cache TTL, potentially leading to stale data and excessive storage usage.