PHPSocialNetwork / phpfastcache

A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
https://www.phpfastcache.com
MIT License
2.36k stars 452 forks source link

deleteItemsByTag() failed to clean up the cache. #865

Closed fantastlcok closed 2 years ago

fantastlcok commented 2 years ago

Configuration

Describe the bug deleteItemsByTag() failed to clean up the cache.

For example there are some caches: key: 'key1', tag: 'tag1' key: 'key2', tag: 'tag1' key: 'key3', tag: 'tag1' key: 'key4', tag: 'tag1'

deleteItemsByTag('tag1') // Delete data by tag getItem('key1')->get(); // still exists

another situation: deleteItem('tag1') // Delete key getItemsByTag('tag1') // View the cache under tag key: 'key2', tag: 'tag1' key: 'key3', tag: 'tag1' key: 'key4', tag: 'tag1' It looks like key1 has been deleted. getItem('key1')->get(); // Can return cached results

I can't reproduce it 100%. I filled Redis with a lot of data and tried to reproduce this problem. But everything works fine. The code with the problem has been running online for a few days before the problem gradually appeared. When I cleared all caches, things went back to normal until the problem started again.

Geolim4 commented 2 years ago

Hello,

Maybe I'm wrong but getItem() will always return an object. Even if it does not exist in backend.

The main difference is that item not found in backend will not be hit (isHit() returns false).

Is that what you trying to report ?

fantastlcok commented 2 years ago

Hello,

Maybe I'm wrong but getItem() will always return an object. Even if it does not exist in backend.

The main difference is that item not found in backend will not be hit (isHit() returns false).

Is that what you trying to report ?

Sorry, I didn't express enough detail. I mean the return value is the correct cached value. In actual code I use it like this:

public function get($key, $group = 'default')
    {
        $key = $this->build_key($key, $group);
        $cache = $this->InstanceCache->getItem($key);
        if ($cache->isHit()) {
            return $cache->get();
        } else {
            return false;
        }
    }
Geolim4 commented 2 years ago

Ok, but I really can't reproduce this bug, I wrote a solid test tests/ItemTags.test.php that tests every aspects of tags of the library and it still pass on v8.1 as well as v9 ?

Can you please write me a full reproducible code please ?

As you can see, the tests on V8 passed 20 days ago: https://app.travis-ci.com/github/PHPSocialNetwork/phpfastcache/builds/248967685

Geolim4 commented 2 years ago

image

fantastlcok commented 2 years ago

Ok, but I really can't reproduce this bug, I wrote a solid test tests/ItemTags.test.php that tests every aspects of tags of the library and it still pass on v8.1 as well as v9 ?

Can you please write me a full reproducible code please ?

As you can see, the tests on V8 passed 20 days ago: https://app.travis-ci.com/github/PHPSocialNetwork/phpfastcache/builds/248967685

I can't reproduce it at the moment, I will continue to troubleshoot the problem and contact you when there is new progress. Thank you for your help.

Geolim4 commented 2 years ago

Thanks, I hope you do understand that it is very hard for me to dig this bug when solid tests are showing that the library works as expected.

Maybe make sure that you don't have concurrent scripts running in the exact same time.

altumcode commented 2 years ago

Hello there,

I've been using phpFastcache for quite some time now in my own products and I can 100% confirm that there is a problem with deleteItemsByTag() function.

It is not something that you can reproduce with certain steps, as it happens randomly.

The deleteItemsByTag() function is extremely unreliable at this point in time and I've had to fully clean the cache manually when such bugs happen (exactly as described by the ticket).

I'm using it with the File adapter + the settings to avoid cache slams.