krakjoe / apcu

APCu - APC User Cache
Other
957 stars 193 forks source link

Feature/apcu_set_ttl Add function to set the TTL of an existing entry atomically #507

Open ignas2526 opened 5 months ago

ignas2526 commented 5 months ago

APCu lacks a nice way to update the TTL of an entry. Currently, you'd have to implement your own critical section, fetch the value of an entry, and then store it back. I think there are many use cases with websites where one would want to create a cache entry with a short life and then extend its lifespan on a subsequent request from the browser.

I think this will be especially useful in combination with apcu_inc, apcu_dec, and apcu_cas. Because calling apcu_store (the only way to extend TTL ATM) after them defeats their purpose.

This PR adds apcu_set_ttl($key, int $ttl = 0): bool. If entry with the $key has been successfully updated, function returns true, else, false.