matthiasmullie / scrapbook

PHP cache library, with adapters for e.g. Memcached, Redis, Couchbase, APC(u), SQL and additional capabilities (e.g. transactions, stampede protection) built on top.
https://www.scrapbook.cash
MIT License
315 stars 27 forks source link

Collections\Utils\PrefixReset::flush : outta-sight-outta-mind #30

Closed bkdotcom closed 6 years ago

bkdotcom commented 6 years ago

Couchbase & Memcached collections extend PrefixReset...

flush() is implemented via " just start a new collection" methodology... This serves to invalidate all keys from the perspective of the collection... it doesn't actually do any trash collection.. the collection could be full of keys set with no expiry (a memory/resource leak)

One use-case for performing a flush may be to free said resources immediatelyrather than rely on the server's LRU mechanism...

PSR-16 defines the clear method as

Wipes clean the entire cache's keys

Which doesn't explicitly state that the resources are freed

Perhaps not necessarily a bug, but something that needs to be documented?

matthiasmullie commented 6 years ago

In terms of behaviour, this was mostly alright - items would no longer be accessible after flush, and $limit would be respected (in that it wouldn't build up and lead to a crash) A flushed collection's stuff would be evicted eventually anyway, but as you said, it would be possible for other thing's to be evicted first (by LRU) I agree that it would be better to actually wipe them out entirely - just submitted that fix!