swayok / alternative-laravel-cache

Replacements for Laravel's redis and file cache stores that properly implement tagging idea
MIT License
169 stars 26 forks source link

Tags within tag lists are duplicating upon each "put" call #22

Closed ardulogic closed 3 years ago

ardulogic commented 3 years ago

Steps to reproduce:

Clear your redis database and run this code:

        Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');
        Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');
        Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');
        Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');
        Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');

You will see two main lists for each tag, which seems correct: image

But within each list, entries are duplicating: image

This shouldn`t happen since the keys are the same.

swayok commented 3 years ago

It is a specifics of a packages used in this package. This package is only a wrapper around Laravel and http://www.php-cache.com/ and I actually have no relation to any of those. It also seems like it is not a bug. Try

Cache::tags(['tag1', 'tag2'])->put('test1', 'test1');
Cache::tags(['tag1', 'tag2'])->put('test1', 'test2');
Cache::tags(['tag1', 'tag2'])->put('test1', 'test3');
Cache::tags(['tag1', 'tag2'])->put('test1', 'test4');

And then next calls will all return test4:

Cache::tags(['tag1', 'tag2'])->get('test1'); 
Cache::tags(['tag2', 'tag1'])->get('test1');    
Cache::tags(['tag1'])->get('test1');           
Cache::tags(['tag2'])->get('test1');            
Cache::get('test1');      

I don't see any specific requirements for tags management in http://www.php-cache.com/en/latest/#tagging docs so it is actually working the way developers of php-cache packages designed. It might be that management of 'clean' version of tagging is more taxing than 'dirty' one. As far as I know http://www.php-cache.com/ cache drivers are all quite popular and well maintained.