Amr
Amr

Reputation: 5159

How can I determine all existing cache keys in Laravel?

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

Upvotes: 1

Views: 4196

Answers (2)

levi
levi

Reputation: 25101

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;
}

Upvotes: 0

zsolt.k
zsolt.k

Reputation: 703

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.)

Upvotes: 1

Related Questions