Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit b16b754

Browse files
committed
Oups...
- Fixed deprecated examples - Added API Version to profiler - Added stopwatch profiling on instance creation
1 parent 1be43cf commit b16b754

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

DataCollector/CacheCollector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function collect(Request $request, Response $response, \Exception $except
6363
'write' => (int) CacheManager::$WriteHits,
6464
],
6565
'coreConfig' => [
66-
'namespacePath' => CacheManager::getNamespacePath()
66+
'namespacePath' => CacheManager::getNamespacePath()
6767
],
6868
];
6969
}

Docs/Example/app/config/phpfastcache-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ php_fast_cache:
4141
leveldbcache:
4242
type: Leveldb
4343
parameters:
44-
path: %kernel.cache_dir%/phpfastcache_leveldb/
44+
path: "%kernel.cache_dir%/phpfastcache_leveldb/"
4545
securityKey: optionnalSetting
4646
ssdbcache:
4747
type: Ssdb

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ php_fast_cache:
1717
filecache:
1818
type: Files
1919
parameters:
20-
path: %kernel.cache_dir%/phpfastcache/
20+
path: "%kernel.cache_dir%/phpfastcache/"
2121
```
2222
* More examples in Docs/Example/app/config
2323

Resources/config/services.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
class: "%php_fast_cache.cache.class%"
99
arguments:
1010
- "%phpfastcache%"
11+
- "@?debug.stopwatch"
1112

1213
phpfastcache.request_collector:
1314
class: "%php_fast_cache.data_collector.class%"

Service/Cache.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,24 @@
55
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
66
use phpFastCache\CacheManager;
77
use phpFastCache\Exceptions\phpFastCacheDriverException;
8+
use Symfony\Component\Stopwatch\Stopwatch;
89

910
/**
1011
* Class Cache
1112
* @package phpFastCache\Bundle\Service
1213
*/
1314
class Cache
1415
{
16+
/**
17+
* @var array
18+
*/
1519
private $drivers = [];
1620

21+
/**
22+
* @var Stopwatch
23+
*/
24+
protected $stopwatch;
25+
1726
/**
1827
* Contains all cache instances
1928
*
@@ -25,12 +34,14 @@ class Cache
2534
* Cache constructor.
2635
*
2736
* @param $drivers
37+
* @param Stopwatch $stopwatch
2838
*
2939
* @throws \phpFastCache\Exceptions\phpFastCacheDriverException
3040
*/
31-
public function __construct($drivers)
41+
public function __construct($drivers, Stopwatch $stopwatch = null)
3242
{
3343
$this->drivers = (array) $drivers[ 'drivers' ];
44+
$this->stopwatch = $stopwatch;
3445
}
3546

3647
/**
@@ -60,6 +71,10 @@ public function createInstance($name, $instance)
6071
*/
6172
public function get($name)
6273
{
74+
if ($this->stopwatch) {
75+
$this->stopwatch->start(__METHOD__ . "('{$name}')");
76+
}
77+
6378
if (!array_key_exists($name, $this->cacheInstances)) {
6479
if (array_key_exists($name, $this->drivers)) {
6580
$this->createInstance($name, CacheManager::getInstance($this->drivers[ $name ][ 'type' ], $this->drivers[ $name ][ 'parameters' ]));
@@ -71,6 +86,9 @@ public function get($name)
7186
}
7287
}
7388

89+
if ($this->stopwatch) {
90+
$this->stopwatch->stop(__METHOD__ . "('{$name}')");
91+
}
7492
return $this->cacheInstances[ $name ];
7593
}
7694

0 commit comments

Comments
 (0)