-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Laravel Version
10.19.0
PHP Version
8.1.22
Database Driver & Version
No response
Description
When using the tags method on a cache store in order to namespace certain tagged items, a memory leak occurs if the flush() method is called on the taggable store.
This appears to occur because when the TaggableStore flushes, it does so by resetting the ids used in the tag namespace, meaning attempts to retrieve the data will now result in a cache miss. However, the cached data is left in place indefinitely and cannot be accessed as the tag ids have now been replaced.
As the Store interface does not expose a way of seeing all possible cache keys, the only fix for this I can think of for this is to have the TaggableStore keep track of the keys within it's namespace, and have it forget() them when flush is called.
Steps To Reproduce
The following code snippet will show a steadily increasing amount of memory in use:
$store = cache()->store('array')->tags(['test']);
while (true) {
$store->flush();
$key = str_replace('.', '', uniqid());
$store->set($key, uniqid());
echo memory_get_usage(true) . PHP_EOL;
}
However I would expect all cache values to be cleared on calling flush() and therefore the memory use remain steady.