Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
stefanbaas opened this issue Aug 31, 2023 · 2 comments
Closed

Comments

@stefanbaas
Copy link

stefanbaas commented Aug 31, 2023

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
Copy link

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

  • Reading and searching out our WIKI
  • Reading and agreed with our Code Of Conduct
  • Reading and understood our Coding Guideline
  • Reading our README
    If everything looks unclear to you, tell us what 😄
    The Phpfastcache Team

@Geolim4
Copy link
Member

Geolim4 commented Aug 31, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants