add redis cache item pool adapter#39
Conversation
| private $createCacheItem; | ||
|
|
||
| /** | ||
| * @var bool |
| } | ||
|
|
||
| $cacheValue = !is_null($cacheValue) ? unserialize($cacheValue) : null; | ||
| $createItem = $this->createCacheItem; |
There was a problem hiding this comment.
you can use call_user_func
| { | ||
|
|
||
| /** | ||
| * @var bool |
| */ | ||
| public function save(CacheItemInterface $item) | ||
| { | ||
| $getItemLifeTime = $this->getItemLifeTime; |
There was a problem hiding this comment.
idem: you can use call_user_func
|
|
||
| $cacheValue = is_string($cacheValue) ? unserialize($cacheValue) : null; | ||
|
|
||
| return call_user_func_array($this->createCacheItem, [$key, $cacheValue, $isHit, $cacheExpire]); |
There was a problem hiding this comment.
Could use
($this->createCacheItem)($key, $cacheValue, $isHit, $cacheExpire)I won't work without first parenthesis couple, bc Php will complain that createCacheItem is not a function
| { | ||
| $this->createCacheItem = \Closure::bind( | ||
| function ($key, $value, $isHit, $cacheExpire) use ($defaultLifetime) { | ||
| $cacheItem = new CacheItem(); |
There was a problem hiding this comment.
Why don't we subclass CacheItem, instead of using closure binding to access protected properties?
There was a problem hiding this comment.
because we can't set the key
There was a problem hiding this comment.
$key is a protected property, so it seems to be designed to be subclassed:
class MyCacheItem extends CacheItem
{
public function __construct($key, $value, $isHit, $cacheExpire, $defaultLifetime) {
// Content of your anonymous function
}
public function getLifetime() {
return $this->expiry;
}
}Then, instead of doing
($this->createCacheItem)($key, $cacheValue, $isHit, $cacheExpire);
($this->getItemLifeTime)($item);You can use
$item = new MyCacheItem($key, $value, $isHit, $cacheExpire, $defaultLifetime);
$item->getLifetime();Did I miss something? Seems more clear for me in this way
There was a problem hiding this comment.
CacheItem is a final class
There was a problem hiding this comment.
Oh… Ooooooh…
It seems to be the official way to set the key…
[Edit]
I'm not the only one to find this surprising
And here
| - 7.0 | ||
| - 5.6 | ||
| - 5.5 | ||
| - 5.4 |
There was a problem hiding this comment.
Should be a new major release because of this BC?
ed9836a to
9d46afa
Compare
9d46afa to
1dae86c
Compare
Add RedisCacheItemPoolAdapter who implements CacheItemPoolInterface
Todo :