V 3.5 RC 1

This commit is contained in:
Romain Neutron
2011-12-05 00:23:28 +01:00
parent 6f1ee368aa
commit 4c5b7eb658
5563 changed files with 466984 additions and 985416 deletions

View File

@@ -0,0 +1,174 @@
<?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.
*/
/**
*
* @package cache
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class cache_opcode_adapter implements cache_opcode_Interface
{
/**
*
*/
const APC = 0;
/**
*
*/
const XCACHE = 1;
/**
*
*/
const NOCACHE = 2;
/**
*
* @var const
*/
protected $cache_method;
/**
*
* @var array
*/
protected static $_static_cache = array();
/**
*
* @var string
*/
protected $prefix;
/**
*
* @return cache_opcode_adapter
*/
public function __construct($prefix = '')
{
if (!http_request::is_command_line() && function_exists('apc_store'))
$this->cache_method = self::APC;
elseif (!http_request::is_command_line() && function_exists('xcache_set'))
$this->cache_method = self::XCACHE;
else
$this->cache_method = self::NOCACHE;
$this->prefix = $prefix;
return $this;
}
/**
*
* @param string $key
* @return mixed
*/
public function get($key)
{
$key = sprintf('%s_%s', $this->prefix, $key);
switch ($this->cache_method)
{
case self::APC:
return apc_fetch($key);
break;
case self::XCACHE:
return xcache_get($key);
break;
default:
return isset(self::$_static_cache[$key]) ? self::$_static_cache[$key] : null;
break;
}
}
/**
*
* @param string $key
* @param mixed $var
* @return cache_opcode_adapter
*/
public function set($key, $var)
{
$key = sprintf('%s_%s', $this->prefix, $key);
switch ($this->cache_method)
{
case self::APC:
if ($this->is_set($key))
apc_delete($key);
apc_store($key, $var);
break;
case self::XCACHE:
if ($this->is_set($key))
$this->un_set ($key);
xcache_set($key, $var);
break;
default:
self::$_static_cache[$key] = $var;
break;
}
return $this;
}
/**
*
* @param string $key
* @return boolean
*/
public function is_set($key)
{
$key = sprintf('%s_%s', $this->prefix, $key);
switch ($this->cache_method)
{
case self::APC:
if (function_exists('apc_exists'))
{
return apc_exists($key);
}
else
{
apc_fetch($key, $succes);
return $succes;
}
break;
case self::XCACHE:
return xcache_isset($key);
break;
default:
return isset(self::$_static_cache[$key]);
break;
}
}
/**
*
* @param string $key
* @return cache_opcode_adapter
*/
public function un_set($key)
{
$key = sprintf('%s_%s', $this->prefix, $key);
switch ($this->cache_method)
{
case self::APC:
apc_delete($key);
break;
case self::XCACHE:
xcache_unset($key);
break;
default:
if (isset(self::$_static_cache[$key]))
unset(self::$_static_cache[$key]);
break;
}
return $this;
}
}

View File

@@ -0,0 +1,27 @@
<?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.
*/
/**
*
* @package
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
interface cache_opcode_interface
{
public function get($key);
public function set($key, $var);
public function is_set($key);
public function un_set($key);
}