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

Cache Statistics #33

Closed darkalchemy closed 6 years ago

darkalchemy commented 6 years ago

Would it be possible to add a method to provide cache stats such as hits, misses and memory used?

matthiasmullie commented 6 years ago

Hey @darkalchemy I won't add such method to the KeyValueStore interface because:

However... Scrapbook is "only a layer of standardization" on top of specific cache clients. While this type of info is hard/impossible to standardize across different adapters, you could fetch these stats from the client directly (if available from the client):

// create \Memcached object pointing to your Memcached server
$client = new \Memcached();
$client->addServer('localhost', 11211);
// create Scrapbook cache object
$cache = new \MatthiasMullie\Scrapbook\Adapters\Memcached($client);

// do operations with Scrapbook
$cache->set('key', 'value');
$cache->get('key');

// get stats directly from Memcached client
var_dump($client->getStats());
darkalchemy commented 6 years ago

I thought that might be the case.

Thank you