1

How can I determine all existing cache keys in a project built with Laravel framework?

Amr
  • 4,809
  • 6
  • 46
  • 60

2 Answers2

1

There is a no way to do this via Laravel Cache library. But you can try to get the keys directly from the cache storage (filesystem, memcached, etc.)

Can Celik
  • 2,050
  • 21
  • 30
zsolt.k
  • 673
  • 4
  • 6
  • 1
    There is a no way via the Laravel Cache library... But you can do this directly from the storage service/files. – zsolt.k Mar 14 '16 at 22:52
0

Assuming you are using the (default) file cache driver, there is no way to get the cache keys, since they are not actually stored.

The key is used to derive a file path, but it's not actually stored.

From the source:

public function put($key, $value, $seconds)
{
    $this->ensureCacheDirectoryExists($path = $this->path($key));

    $result = $this->files->put(
        $path, $this->expiration($seconds).serialize($value), true
    );

    if ($result !== false && $result > 0) {
        $this->ensurePermissionsAreCorrect($path);

        return true;
    }

    return false;
}
levi
  • 23,693
  • 18
  • 59
  • 73