Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nSeixas77's avatar

File cache keys

Good morning everyone!

I'm currently using file based cache, and I need to list all the existing keys.

Apparently there's no easy way of doing it...I thought about looping through the files, however even the files don't have the key name (the one I specified in the Cache::Remember function) in the file name or in the content of the file itself.

Anyone knows if it's possible somehow to archive this? Or is not possible at all?

Thank you.

Regards, Nuno

0 likes
1 reply
neilstee's avatar
neilstee
Best Answer
Level 34

@nseixas77 can you check this:

$storage = Cache::getStore(); // will return instance of FileStore
$filesystem = $storage->getFilesystem(); // will return instance of Filesystem

$keys = [];
foreach ($filesystem->allFiles('') as $file1) {
  foreach ($filesystem->allFiles($file1) as $file2) {
    $keys = array_merge($keys, $filesystem->allFiles($file1 . '/' . $file2));
  }
}

Source: https://stackoverflow.com/a/31791530

1 like

Please or to participate in this conversation.