예제 #1
0
 /**
  * @dataProvider keyPrefixProvider
  */
 public function testDeleteCallsClient($key, $expectedKey, $prefix = null)
 {
     $this->client->expects($this->once())->method('delete')->with($this->equalTo($expectedKey));
     $cache = new Cache($this->client);
     if ($prefix) {
         $cache->setPrefix($prefix);
     }
     $cache->delete($key);
 }
 public function register(Application $app)
 {
     // defaults (these can be overridden in the container)
     $app['be_cache.type'] = 'memcache';
     $app['be_cache.host'] = '127.0.0.1';
     $app['be_cache.port'] = '11211';
     $app['be_cache.stats'] = true;
     $app['be_cache.prefix'] = '';
     // register the client
     $app['be_cache.client'] = $app->share(function () use($app) {
         $client = null;
         switch (strtolower($app['be_cache.type'])) {
             default:
                 throw new \Exception('Invalid be_cache.type');
                 break;
             case 'file':
             case 'filecache':
                 if (!$app['be_cache.path'] || !is_writable($app['be_cache.path'])) {
                     throw new \Exception('$app[\'be_cache.path\'] must be writable.');
                 }
                 $client = new FilecacheClient($app['be_cache.path']);
                 if ($app['be_cache.stats']) {
                     $stats = new FilecacheStatisticsTracker($app['be_cache.path']);
                     $client->setStatisticsTracker($stats);
                 }
                 break;
             case 'memcache':
                 $memcache = new \Memcache();
                 $memcache->addserver($app['be_cache.host'], $app['be_cache.port']);
                 $client = new MemcacheClient($memcache);
                 break;
             case 'apc':
                 $client = new APCClient();
                 break;
         }
         return $client;
     });
     //register the service
     $app['be_cache'] = $app->share(function () use($app) {
         $cache = new Cache($app['be_cache.client']);
         $cache->setPrefix($app['be_cache.prefix']);
         return $cache;
     });
 }