apcu
apcu copied to clipboard
Ideas for improving apcu_entry()
Hello,
while working on stampede protection for a future version of Symfony Cache, I wanted to share two ideas that might improve the behavior of apcu_entry()
:
- the
$ttl
value might not be known at fetch-time. It would be great to allow changing it from the callback. It could be done via a new 2nd argument, passed by reference to the callback. - as stated in the doc,
apcu_entry()
locks concurrent read-access. But this behavior breaks stampede protection, as this lock prevents concurrent access from serving any "stale" value. An idea to improve this behavior could be to add a 3rd argument to the function, called$beta
, defaulting to zero for BC. When provided,$beta
would trigger probabilistic early expiration (providingINF
would force immediate expiration).