Maslosoft Cache API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
<?php
/**
* This software package is licensed under New BSD license.
*
* @package maslosoft/cache
* @licence New BSD
*
* @copyright Copyright (c) Peter Maselkowski <pmaselkowski@gmail.com>
*
*/
namespace Maslosoft\Cache\Adapters;
use Maslosoft\Cache\Interfaces\CacheAdapterInterface;
/**
* Apc and Apcu cache adapter
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
class Apc implements CacheAdapterInterface
{
private $apcu = false;
public function __construct()
{
$this->apcu = extension_loaded('apcu');
}
public function get($key)
{
if ($this->apcu)
{
return apcu_fetch((string) $key);
}
return apc_fetch((string) $key);
}
public function has($key)
{
if ($this->apcu)
{
return apcu_exists((string) $key);
}
return apc_exists((string) $key);
}
public function isAvailable()
{
return (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled') == 1;
}
public function set($key, $data, $timeout = null)
{
if ($this->apcu)
{
return apcu_store((string) $key, $data, $timeout);
}
return apc_store((string) $key, $data, $timeout);
}
public function clear()
{
if ($this->apcu)
{
return apcu_clear_cache();
}
return apc_clear_cache();
}
public function remove($key)
{
if ($this->apcu)
{
return apcu_delete((string) $key);
}
return apc_delete((string) $key);
}
}
API documentation generated by ApiGen