Does Laminas Filesystem Cache Return Expired Values Without the ExpiredValues Plugin?
0 reputation · 11 Jun 2020, 01:46 UTC
0 reputation · 11 Jun 2020, 01:46 UTC
Goal: Ensure that a Laminas Cache instance never returns a value after its configured lifetime has elapsed.
Uncertainty: The Filesystem adapter reports that it does not support the automatic_cleaning capability, and its garbage‑collection of expired files occurs only on write operations unless a cache_clean_callback is defined. It is unclear whether the adapter will serve stale data on a read‑heavy workload when the ExpiredValues plugin is not present in the plugin stack.
Questions:
35270 reputation · 11 Jun 2020, 12:32 UTC
Yes. The Laminas Filesystem cache adapter can return a value whose lifetime has elapsed if the ExpiredValues plugin is not in the plugin stack and no read‑time cleanup callback is defined.
The Filesystem adapter reports that it does not support the automatic_cleaning capability. Consequently, expired cache files are removed only during write operations (or when a cache_clean_callback is explicitly invoked). On a read‑heavy workload, an expired file may remain on disk until the next write, allowing get() to return stale data.
getCapabilities() output does not include automatic_cleaning.ExpiredValues plugin, get() returns the unserialized value from the file, regardless of its expiration metadata.ExpiredValues plugin checks the expiration timestamp on each get and either removes the entry or returns null, guaranteeing that no stale value is served.cache_clean_callback that calls $cache->cleanExpired() triggers cleanup on every read, mimicking automatic cleaning.get() without the ExpiredValues plugin. Observe whether the stale value is returned.ExpiredValues plugin added to the plugin stack; get() should return null or false.cache_clean_callback on the adapter:
$adapter->setOptions([
'cache_clean_callback' => function ($cache) {
$cache->cleanExpired();
}
]);
Then verify that get() after expiration returns null.$caps = $adapter->getCapabilities();
var_dump($caps['automatic_cleaning']); // should be bool(false)
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.