Add IMultiReadStorage
fprochazka opened this issue · 5 comments
I propose adding a new interface IMultiReadStorage
that will extend Nette\Caching\IStorage
and it's implementation would mean that the cache can utilize the storage more effectively. Because reading 100 keys from memory cache at once is more effective than 100 requests.
Yes, this is a real world use-case, tested in our application and a friend on Posobota also told me he's using this approach.
We did implement our own IMultiReadStorage
to Kdyby/Redis, but I wanna have a "standard" interface for my storage.
Also to the cache class should be added new method
class Cache
{
public function multiLoad(array $keys)
{
if ($this->storage instanceof IMultiReadStorage) {
return $this->storage->multiRead($keys);
}
$result = array();
foreach ($keys as $key) {
$result[$key] = $this->load($key);
}
return $result;
}
To discuss:
- should this be in Nette? (Should I send a pullrequest?)
- better name for
IMultiReadStorage
? - implementation details
What about Batch or Bulk instead of Multi?
IBulkLoadStorage::bulkLoad
to keep the convention (not Read
)
- Add
IBulkSaveStorage::bulkSave
?
I don't think bulk save is neccesary.