apcu icon indicating copy to clipboard operation
apcu copied to clipboard

Cache Value update without Hits-Resetting

Open markus-hsk opened this issue 7 years ago • 2 comments

I've encoutered a "problem" on updating cached keys. If i use apcu_store, the hits-counter is resetted to 0 and the creation time is also new. It seams, that the key is replaced. This might be intentional.

My question, is where a way to keep the hit counter and creation time but also update the value? apcu_cas only works for integer values. It does not allow strings or anything else. And besides, it also resets the creation time.

My testing script:

apcu_store('KEY_A', 'A');
apcu_store('KEY_C', 0);

for($i = 0; $i < 5; $i++)
{
    apcu_fetch('KEY_A');
    
    apcu_store('KEY_B', $i);
    apcu_fetch('KEY_B');
    
    sleep(2);
    
    apcu_cas('KEY_C', $i, $i+1);
    apcu_fetch('KEY_C');
}

The result:

apcu_issue

Serverinfos:

APCu Version | 5.1.8 PHP Version | 7.1.6 Server Software | Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/7.1.6

markus-hsk avatar Feb 20 '18 10:02 markus-hsk

I came to report the same issue above (PHP 7.2.10, APCu 5.1.12). As things are now, using a fetch and store pair, most the details (hits, last access, last modified, created at) are useless. If nothing else it would be nice if "Created at" at least stuck around.

TTMikeK avatar Oct 16 '18 16:10 TTMikeK

Treating store as an update rather than replace would muddy the semantics with regard to the per-entry hard TTL. Right now it is against the creation time, which currently would be the time where the store was performed. It's not clear how it would behave after the proposed change. Would it be against the original creation time? Would it be against the modification time?

nikic avatar Oct 16 '18 19:10 nikic