Skip to content

[5.0.1] Empty cache key requested #46

@wnateg

Description

@wnateg

PHP & Platform

8.2

Database

No response

Laravel version

11.51

Have you done this?

  • I have checked my logs and I'm sure is a bug in this package.
  • I can reproduce this bug in isolation (vanilla Laravel install)
  • I can suggest a workaround as a Pull Request

Expectation

Without using the "as" method, it still requests the key property of the Cache class, leading to an empty cache key being requested.

Thank you.

Description

I believe this function is the culprit. Sometimes $this->cache->key is empty.

protected function retrieveResultsFromCache(string $key): array
{
    // If the cache should be regenerated, just return empty results.
    if ($this->cache->regenFactor === (bool) value($this->cache->regenerate)) {
        return [$key => null, $this->cache->key => null];
    }

    return $this->repository->getMultiple([$key, $this->cache->key]);
}

Reproduction

\Event::listen(\Illuminate\Cache\Events\CacheMissed::class, function ($e) {
        dump($e->key);
    });

\App\Models\Platform::cache(now()->addMinutes(10))->get();

Two keys are dumped:
"cache-query|**************"
""

Stack trace & logs

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions