public function attachCache($cacheService)
{
static $mode, $collector, $hasAttachd = array();
if (in_array($cacheService, $hasAttachd)) {
return;
}
$hasAttachd[] = $cacheService;
if (!$this->shouldCollect('cache', false)) {
return;
}
if (!is_string($cacheService)) {
throw new \Exception('The parameter must be a cache service name.');
}
if (!$mode) {
$mode = $this->config->options->cache->get('mode', 0);
}
if (!$collector) {
$mc = null;
if ($this->hasCollector('messages')) {
$mc = $this->getCollector('messages');
}
$collector = new CacheCollector($mode, $mc);
$this->addCollector($collector);
}
$backend = $this->di->get($cacheService);
if ($backend instanceof Multiple || $backend instanceof Backend) {
if ($this->shouldCollect('cache', false)) {
$this->di->remove($cacheService);
$self = $this;
$this->di->set($cacheService, function () use($self, $backend, $collector) {
return $self->createProxy(clone $backend, $collector);
});
}
}
}