Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add redis cache item pool adapter#39

Merged
lnahiro merged 2 commits into
masterfrom
feature/add-redis-cache-item-pool-interface
Jul 31, 2017
Merged

add redis cache item pool adapter#39
lnahiro merged 2 commits into
masterfrom
feature/add-redis-cache-item-pool-interface

Conversation

@lnahiro
Copy link
Copy Markdown
Contributor

@lnahiro lnahiro commented Jun 30, 2017

Add RedisCacheItemPoolAdapter who implements CacheItemPoolInterface

Todo :

  • Tests

private $createCacheItem;

/**
* @var bool
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closure

}

$cacheValue = !is_null($cacheValue) ? unserialize($cacheValue) : null;
$createItem = $this->createCacheItem;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use call_user_func

{

/**
* @var bool
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closure

*/
public function save(CacheItemInterface $item)
{
$getItemLifeTime = $this->getItemLifeTime;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idem: you can use call_user_func

Copy link
Copy Markdown

@b-viguier b-viguier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions/remarks, but ok 😄


$cacheValue = is_string($cacheValue) ? unserialize($cacheValue) : null;

return call_user_func_array($this->createCacheItem, [$key, $cacheValue, $isHit, $cacheExpire]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we subclass CacheItem, instead of using closure binding to access protected properties?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we can't set the key

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CacheItem is a final class

Copy link
Copy Markdown

@b-viguier b-viguier Jul 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread .travis.yml
- 7.0
- 5.6
- 5.5
- 5.4
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a new major release because of this BC?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@lnahiro lnahiro force-pushed the feature/add-redis-cache-item-pool-interface branch 2 times, most recently from ed9836a to 9d46afa Compare July 28, 2017 09:56
@lnahiro lnahiro force-pushed the feature/add-redis-cache-item-pool-interface branch from 9d46afa to 1dae86c Compare July 31, 2017 10:04
@lnahiro lnahiro merged commit e5d46ab into master Jul 31, 2017
@lnahiro lnahiro deleted the feature/add-redis-cache-item-pool-interface branch July 31, 2017 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants