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

Cache clear() not working with Redis, getItem() still returns data #903

Closed stefanbaas closed 9 months ago

stefanbaas commented 11 months ago

The cache clear() function is not working correctly with Redis, getItem('{cachekey}') still returns data, after i cleared the cache with the clear() function. I'm using version 9.1.3. Even after a page refresh the data is not deleted.

use Phpfastcache\CacheManager;
$_cache = CacheManager::getInstance('redis', new Config(array(
    'host' => '127.0.0.1',
    'port' => 6379,
    'password' => '',
    'database' => 0,
    'itemDetailedDate' => true
))); 

// Clear all cache
$_cache->clear();

// Get cache data
$cacheKey = "test";
$item = $_cache->getItem($cacheKey);
$data = $item->get(); // I still get data after $_cache->clear()

When i delete the item with the following function it works correctly, but i want to delete the whole cache. It's strange because $_cache->getItems() returns an empty array, but $_cache->getItem("test") is returning data. $_cache->deleteItem("test");

github-actions[bot] commented 11 months ago

Hello curious contributor ! Since it seems to be your first contribution, make sure that you've been:

Geolim4 commented 11 months ago

Hello

As per PSR6: https://www.php-fig.org/psr/psr-6/

 * Returns a Cache Item representing the specified key.
*
* This method must always return a CacheItemInterface object, even in case of
* a cache miss. It MUST NOT return null.
*

It is by design so.

Cheers, Georges