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

MemoryStore size/limit with collections #29

Closed bkdotcom closed 6 years ago

bkdotcom commented 6 years ago

MemoryStore limit enforcement goes out the window when collections are created

$adapter = new MemoryStore(1000);
$collectionFoo = $adapter->getCollection('foo');
$collectionBar = $adapter->getCollection('bar');

// $adapter, $collectionFoo, & $collectionBar all have independent limits of 1000
// we requested a limit of 1000... but we can go 3 times over
matthiasmullie commented 6 years ago

Nice catch! I fixed this, though slightly different than what you suggested: if new data is added to collections, it can also lead to evictions in the parent. That is fair game, IMO: other cache backends will also evict whatever they deem necessary, regardless of whether it's in a parent or child (these collections are mostly artificial anyway, implemented via prefixing - they're not separate cache servers) En plus: it's not about data persistence (especially not in a "memory store") - it's ok for data to fall out of cache (a cache eviction is just meant to prevent the app from blowing up if one attempts to store too much data)

bkdotcom commented 6 years ago

Awesome!

MatthiasMullie\Scrapbook\Adapters\Collections\MemoryStore also needs to extend flush()

der... was thinking that flush should also update $size... but nothing is actually immediately "evicted"... related to #30