Skip to content

Commit 94bd4e0

Browse files
committed
Implementing CacheItemPoolInterface
1 parent 14316cc commit 94bd4e0

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

src/Cache/LoggingCachePool.php

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
namespace Cache\CacheBundle\Cache;
1313

14-
use Aequasi\Cache\CacheItem;
15-
use Aequasi\Cache\CachePool;
1614
use Psr\Cache\CacheItemInterface;
1715
use Psr\Cache\CacheItemPoolInterface;
16+
use Psr\Cache\InvalidArgumentException;
1817

1918
/**
2019
* @author Aaron Scherer <[email protected]>
2120
*/
22-
class LoggingCachePool extends CachePool
21+
class LoggingCachePool implements CacheItemPoolInterface
2322
{
2423
/**
2524
* @var array $calls
@@ -70,7 +69,7 @@ public function deleteItem($key)
7069

7170
public function save(CacheItemInterface $item)
7271
{
73-
$itemClone = clone $item;
72+
$itemClone = clone $item;
7473
$itemClone->set(sprintf('<DATA:%s', gettype($item->get())));
7574

7675
$call = $this->timeCall(__FUNCTION__, [$item]);
@@ -82,21 +81,68 @@ public function save(CacheItemInterface $item)
8281

8382
/**
8483
* @param string $name
85-
* @param $arguments
84+
* @param array $arguments
8685
*
8786
* @return object
8887
*/
89-
private function timeCall($name, $arguments)
88+
private function timeCall($name, array $arguments = null)
9089
{
9190
$start = microtime(true);
9291
$result = call_user_func_array([$this->cachePool, $name], $arguments);
9392
$time = microtime(true) - $start;
9493

95-
$object = (object) compact('name', 'arguments', 'start', 'time', 'result');
94+
$object = (object)compact('name', 'arguments', 'start', 'time', 'result');
9695

9796
return $object;
9897
}
9998

99+
public function getItems(array $keys = [])
100+
{
101+
$call = $this->timeCall(__FUNCTION__, [$keys]);
102+
$result = $call->result;
103+
$call->result = sprintf('<DATA:%s>', gettype($result));
104+
105+
$this->calls[] = $call;
106+
107+
return $result;
108+
}
109+
110+
public function clear()
111+
{
112+
$call = $this->timeCall(__FUNCTION__);
113+
$this->calls[] = $call;
114+
115+
return $call->result;
116+
}
117+
118+
public function deleteItems(array $keys)
119+
{
120+
$call = $this->timeCall(__FUNCTION__, [$keys]);
121+
$this->calls[] = $call;
122+
123+
return $call->result;
124+
}
125+
126+
public function saveDeferred(CacheItemInterface $item)
127+
{
128+
$itemClone = clone $item;
129+
$itemClone->set(sprintf('<DATA:%s', gettype($item->get())));
130+
131+
$call = $this->timeCall(__FUNCTION__, [$item]);
132+
$call->arguments = ['<CacheItem>', $itemClone];
133+
$this->calls[] = $call;
134+
135+
return $call->result;
136+
}
137+
138+
public function commit()
139+
{
140+
$call = $this->timeCall(__FUNCTION__);
141+
$this->calls[] = $call;
142+
143+
return $call->result;
144+
}
145+
100146
/**
101147
* @return array
102148
*/

src/DependencyInjection/Compiler/DoctrineSupportCompilerPass.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ protected function enableDoctrineSupport(array $config)
8989
*/
9090
private function hasDoctrine()
9191
{
92-
return $this->container->hasAlias('doctrine.orm.entity_manager') ||
93-
$this->container->hasAlias('doctrine_mongodb.document_manager');
92+
return
93+
$this->container->hasAlias('doctrine.orm.entity_manager') ||
94+
$this->container->hasAlias('doctrine_mongodb.document_manager');
9495
}
9596
}

src/Resources/config/collector.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)