Conversation
5ee1b40 to
c25b0c1
Compare
| * @param array | ||
| * @param callable | ||
| * @return array | ||
| */ |
There was a problem hiding this comment.
Does it make sense to have one fallback? Woulldn't make more sense to have fallback for each key? Or support both?
There was a problem hiding this comment.
key is passed as a first parameter to the fallback.
There was a problem hiding this comment.
Yes but then you can't easily reuse callback for load and bulkLoad.
There was a problem hiding this comment.
So each time you call bulkLoad you will build an array of callbacks? that does not sound right.
There was a problem hiding this comment.
What if you want e.g. three values whose value are calculated in a different way? You would have to build this logic by if/switch branching inside the callback. That feels a bit ugly...
There was a problem hiding this comment.
|
I don't think bulk reuse for single operation is a good idea, for performance reasons. |
| if (!is_scalar($key)) { | ||
| throw new Nette\InvalidArgumentException('Only scalar keys are allowed in a bulkLoad method.'); | ||
| } | ||
| } |
There was a problem hiding this comment.
Replaces whole line with
$storageKeys = array_map([$this, 'generateKey'], $keys);|
Have you seen how doctrine/cache handles this? https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/CacheProvider.php |
| * @param string key | ||
| * @return array key => value pairs, missing items are omitted | ||
| */ | ||
| function bulkRead(array $keys); |
There was a problem hiding this comment.
TODO: consider returning [$value1, $value2] instead of more complex [$key1 => $value1, $key2 => $value2]
There was a problem hiding this comment.
Storage would have to maintain the item order and check for missing values. This is easier.
There was a problem hiding this comment.
Yes but the implementation in Cache would be simpler and faster.
There was a problem hiding this comment.
Yes but the same logic would have to be in the storage itself.
There was a problem hiding this comment.
That would depend on the storage. Now you assume that no storage can implement this efficiently.
There was a problem hiding this comment.
Yes, I do assume that. Or do you know any storage that doesn't need that logic?
|
The ideas is awesome, but the implementation needs a lot polishing. |
| require __DIR__ . '/Cache.php'; | ||
|
|
||
| //storage without bulk load support | ||
| test(function () { |
There was a problem hiding this comment.
I think dg uses test(function () { // storage without bulk load support pattern
|
btw, the performance impact of bulkRead reuse for a single read is about 10-20% |
| throw new Nette\InvalidArgumentException('Only scalar keys are allowed in a bulkLoad method.'); | ||
| } | ||
| } | ||
| $storageKeys = array_map([$this, 'generateKey'], $keys); |
There was a problem hiding this comment.
Drop this line, replace all usages of $storage with $this->storage
|
updated - storages are optimized |
| { | ||
| $keys = array_combine(array_map(function ($key) { | ||
| return urlencode($this->prefix . $key); | ||
| }, $keys), $keys); |
There was a problem hiding this comment.
Replace with
$prefixedKeys = array_map(function ($key) { return urlencode($this->prefix . $key); });
$keys = array_combine($prefixedKeys, $keys); // TODO: can we remove this?
$metas = $this->memcached->getMulti($prefixedKeys);0aed862 to
a0c400e
Compare
Uh oh!
There was an error while loading. Please reload this page.