rename cache service

This commit is contained in:
Nicolas Le Goff
2012-01-19 16:06:30 +01:00
parent 1a742a826e
commit 61d93bd03b
4 changed files with 300 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Service\Cache;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ApcCache extends ServiceAbstract implements ServiceInterface
{
public function getScope()
{
return 'cache';
}
/**
*
* @return Cache\ApcCache
*/
public function getService()
{
if (!extension_loaded('apc'))
{
throw new \Exception('The APC cache requires the APC extension.');
}
$registry = $this->getRegistry();
$service = new CacheService\ApcCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
}
public function getType()
{
return 'apc';
}
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
}

View File

@@ -0,0 +1,67 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Service\Cache;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
/**
* Array cache
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class ArrayCache extends ServiceAbstract implements ServiceInterface
{
public function getScope()
{
return 'cache';
}
/**
*
* @return Cache\ApcCache
*/
public function getService()
{
$registry = $this->getRegistry();
$service = new CacheService\ArrayCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
}
public function getType()
{
return 'array';
}
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
}

View File

@@ -0,0 +1,92 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Service\Cache;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Memcache extends ServiceAbstract implements ServiceInterface
{
const DEFAULT_HOST = "localhost";
const DEFAULT_PORT = "11211";
protected $host;
protected $port;
public function getScope()
{
return 'cache';
}
/**
*
* @return Cache\ApcCache
*/
public function getService()
{
if (!extension_loaded('memcache'))
{
throw new \Exception('The Memcache cache requires the Memcache extension.');
}
$this->host = isset($this->options["host"]) ? $this->options["host"] : self::DEFAULT_HOST;
$this->port = isset($this->options["port"]) ? $this->options["port"] : self::DEFAULT_PORT;
$memchache = new \Memcache();
$memchache->connect($this->host, $this->port);
$registry = $this->getRegistry();
$service = new CacheService\MemcacheCache($memchache);
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
}
public function getType()
{
return 'memcache';
}
public function getHost()
{
return $this->host;
}
public function getPort()
{
return $this->port;
}
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
}

View File

@@ -0,0 +1,70 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Service\Cache;
use Alchemy\Phrasea\Core,
Alchemy\Phrasea\Core\Service,
Alchemy\Phrasea\Core\Service\ServiceAbstract,
Alchemy\Phrasea\Core\Service\ServiceInterface;
use Doctrine\Common\Cache as CacheService;
/**
* it's just like array cache
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class XcacheCache extends ServiceAbstract implements ServiceInterface
{
public function getScope()
{
return 'cache';
}
/**
*
* @return Cache\ApcCache
*/
public function getService()
{
if (!extension_loaded('xcache'))
{
throw new \Exception('The XCache cache requires the XCache extension.');
}
$registry = $this->getRegistry();
$service = new CacheService\XcacheCache();
$service->setNamespace($registry->get("GV_sit", ""));
return $service;
}
public function getType()
{
return 'xcache';
}
private function getRegistry()
{
$registry = $this->getDependency("registry");
if (!$registry instanceof \registryInterface)
{
throw new \Exception(sprintf('Registry dependency does not implement registryInterface for %s service', $this->name));
}
return $registry;
}
}