tedious / Stash

The place to keep your cache.
http://www.stashphp.com
BSD 3-Clause "New" or "Revised" License
961 stars 133 forks source link

Add an ability to disable expiration time randomization. #419

Open beeyev opened 1 year ago

beeyev commented 1 year ago

The library has this code to slightly change the expiration time.

$expirationDiff = rand(0, floor($cacheTime * .15));
$expiration -= $expirationDiff;

I know the reason, it's also discussed here.

Could you please add an ability to disable this feature when it's needed? Developers should be able to set precise TTL when they really want to do that.

tedivm commented 1 year ago

You can disable this at the Pool or Item level.

$pool->setInvalidationMethod(Stash\Invalidation::NONE)

This can be done on the item level as well. You may want to read through all the invalidation methods to see which one fits your needs most.

beeyev commented 1 year ago

I checked it, but this parameter does not change the behavior I mentioned.

Here

private function executeSet($data, $time)
    {
       ...

        // We need to be able to disable this part
        if ($cacheTime > 0) {
            $expirationDiff = rand(0, floor($cacheTime * .15));
            $expiration -= $expirationDiff;
        }