setCache() публичный Метод

Sets the Cache class
public setCache ( DeviceDetector\Cache\Cache | CacheProvider $cache )
$cache DeviceDetector\Cache\Cache | Doctrine\Common\Cache\CacheProvider
 public function __construct(RequestStack $stack, CacheProvider $cache, $deviceDetectorOptions)
 {
     $this->cacheManager = $cache;
     $this->requestStack = $stack;
     $this->setOptions($deviceDetectorOptions);
     if (null !== $this->requestStack && $this->requestStack->getCurrentRequest()) {
         $userAgent = $this->requestStack->getCurrentRequest()->headers->get('User-Agent');
     } else {
         $userAgent = '';
     }
     $this->deviceDetector = new \DeviceDetector\DeviceDetector($userAgent);
     $this->deviceDetector->setCache($this->getCacheManager());
     if (!empty($this->deviceDetectorOptions['discard_bot_information'])) {
         $this->deviceDetector->discardBotInformation();
     }
     if (!empty($this->deviceDetectorOptions['skip_bot_detection'])) {
         $this->deviceDetector->skipBotDetection();
     }
     $this->deviceDetector->parse();
 }
Пример #2
0
 public function testCacheSetAndGet()
 {
     if (!extension_loaded('memcache') || !class_exists('\\Doctrine\\Common\\Cache\\MemcacheCache')) {
         $this->markTestSkipped('memcache not enabled');
     }
     $dd = new DeviceDetector();
     $memcacheServer = new \Memcache();
     $memcacheServer->connect('localhost', 11211);
     $dd->setCache(new \Doctrine\Common\Cache\MemcacheCache($memcacheServer));
     $this->assertInstanceOf('Doctrine\\Common\\Cache\\MemcacheCache', $dd->getCache());
 }
Пример #3
0
 /**
  * Returns a Singleton instance of DeviceDetector for the given user agent
  * @param string $userAgent
  * @return DeviceDetector
  */
 public static function getInstance($userAgent)
 {
     if (array_key_exists($userAgent, self::$deviceDetectorInstances)) {
         return self::$deviceDetectorInstances[$userAgent];
     }
     $deviceDetector = new DeviceDetector($userAgent);
     $deviceDetector->discardBotInformation();
     $deviceDetector->setCache(new DeviceDetectorCache(86400));
     $deviceDetector->parse();
     self::$deviceDetectorInstances[$userAgent] = $deviceDetector;
     return $deviceDetector;
 }
<?php

/*
 * Piwik cache init
 */
include 'bootstrap.php';
use DeviceDetector\DeviceDetector;
use Doctrine\Common\Cache;
/*
 * File
 */
$cache = new Cache\PhpFileCache('.tmp/piwik');
$dd = new DeviceDetector();
$dd->setCache($cache);
$dd->setUserAgent('test');
$dd->parse();
// /*
//  * Apc
//  */
// $cache = new Cache\ApcCache();
// $cache->setNamespace('piwik_device');
// $dd = new DeviceDetector();
// $dd->setCache($cache);
// $dd->setUserAgent('test');
// $dd->parse();