mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 09:49:22 +02:00
* add @method annotations to Cache class
* code beautify
This commit is contained in:
parent
933b25194c
commit
7b770e09f7
@ -10,6 +10,14 @@
|
|||||||
*/
|
*/
|
||||||
defined('MYAAC') or die('Direct access not allowed!');
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Cache
|
||||||
|
*
|
||||||
|
* @method set($key, $var, $ttl = 0)
|
||||||
|
* @method get($key)
|
||||||
|
* @method fetch($key, &$var)
|
||||||
|
* @method delete($key)
|
||||||
|
*/
|
||||||
class Cache
|
class Cache
|
||||||
{
|
{
|
||||||
static private $instance;
|
static private $instance;
|
||||||
|
@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
|||||||
|
|
||||||
class Cache_APC
|
class Cache_APC
|
||||||
{
|
{
|
||||||
private $prefix = '';
|
private $prefix;
|
||||||
private $enabled;
|
private $enabled;
|
||||||
|
|
||||||
public function __construct($prefix = '')
|
public function __construct($prefix = '')
|
||||||
@ -31,8 +31,9 @@ class Cache_APC
|
|||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($this->prefix . $key, $tmp))
|
if($this->fetch($this->prefix . $key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -48,5 +49,4 @@ class Cache_APC
|
|||||||
public function enabled() {
|
public function enabled() {
|
||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
|||||||
|
|
||||||
class Cache_APCu
|
class Cache_APCu
|
||||||
{
|
{
|
||||||
private $prefix = '';
|
private $prefix;
|
||||||
private $enabled;
|
private $enabled;
|
||||||
|
|
||||||
public function __construct($prefix = '')
|
public function __construct($prefix = '')
|
||||||
@ -31,8 +31,9 @@ class Cache_APCu
|
|||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($this->prefix . $key, $tmp))
|
if($this->fetch($this->prefix . $key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -49,4 +50,3 @@ class Cache_APCu
|
|||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -30,8 +30,9 @@ class Cache_eAccelerator
|
|||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($this->prefix . $key, $tmp))
|
if($this->fetch($this->prefix . $key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -48,4 +49,3 @@ class Cache_eAccelerator
|
|||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
@ -11,8 +11,8 @@ defined('MYAAC') or die('Direct access not allowed!');
|
|||||||
|
|
||||||
class Cache_File
|
class Cache_File
|
||||||
{
|
{
|
||||||
private $prefix = '';
|
private $prefix;
|
||||||
private $dir = '';
|
private $dir;
|
||||||
private $enabled;
|
private $enabled;
|
||||||
|
|
||||||
public function __construct($prefix = '', $dir = '') {
|
public function __construct($prefix = '', $dir = '') {
|
||||||
@ -25,17 +25,21 @@ class Cache_File
|
|||||||
{
|
{
|
||||||
$file = $this->_name($key);
|
$file = $this->_name($key);
|
||||||
file_put_contents($file, $var);
|
file_put_contents($file, $var);
|
||||||
if($ttl != 0)
|
|
||||||
|
if($ttl !== 0) {
|
||||||
touch($file, time() + $ttl);
|
touch($file, time() + $ttl);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
touch($file, time() + 24 * 60 * 60);
|
touch($file, time() + 24 * 60 * 60);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($key, $tmp))
|
if($this->fetch($key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -43,8 +47,9 @@ class Cache_File
|
|||||||
public function fetch($key, &$var)
|
public function fetch($key, &$var)
|
||||||
{
|
{
|
||||||
$file = $this->_name($key);
|
$file = $this->_name($key);
|
||||||
if(!file_exists($file) || filemtime($file) < time())
|
if(!file_exists($file) || filemtime($file) < time()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$var = file_get_contents($file);
|
$var = file_get_contents($file);
|
||||||
return true;
|
return true;
|
||||||
@ -53,8 +58,9 @@ class Cache_File
|
|||||||
public function delete($key)
|
public function delete($key)
|
||||||
{
|
{
|
||||||
$file = $this->_name($key);
|
$file = $this->_name($key);
|
||||||
if(file_exists($file))
|
if(file_exists($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enabled() {
|
public function enabled() {
|
||||||
@ -62,7 +68,6 @@ class Cache_File
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function _name($key) {
|
private function _name($key) {
|
||||||
return sprintf("%s%s%s", $this->dir, $this->prefix, sha1($key));
|
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -42,8 +42,9 @@ class Cache_PHP
|
|||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($key, $tmp))
|
if($this->fetch($key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -51,8 +52,9 @@ class Cache_PHP
|
|||||||
public function fetch($key, &$var)
|
public function fetch($key, &$var)
|
||||||
{
|
{
|
||||||
$file = $this->_name($key);
|
$file = $this->_name($key);
|
||||||
if(!file_exists($file) || filemtime($file) < time())
|
if(!file_exists($file) || filemtime($file) < time()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@include $file;
|
@include $file;
|
||||||
$var = isset($var) ? $var : null;
|
$var = isset($var) ? $var : null;
|
||||||
@ -62,8 +64,9 @@ class Cache_PHP
|
|||||||
public function delete($key)
|
public function delete($key)
|
||||||
{
|
{
|
||||||
$file = $this->_name($key);
|
$file = $this->_name($key);
|
||||||
if(file_exists($file))
|
if(file_exists($file)) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enabled() {
|
public function enabled() {
|
||||||
@ -73,5 +76,4 @@ class Cache_PHP
|
|||||||
private function _name($key) {
|
private function _name($key) {
|
||||||
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key) . '.php');
|
return sprintf('%s%s%s', $this->dir, $this->prefix, sha1($key) . '.php');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
@ -12,7 +12,7 @@ defined('MYAAC') or die('Direct access not allowed!');
|
|||||||
|
|
||||||
class Cache_XCache
|
class Cache_XCache
|
||||||
{
|
{
|
||||||
private $prefix = '';
|
private $prefix;
|
||||||
private $enabled;
|
private $enabled;
|
||||||
|
|
||||||
public function __construct($prefix = '') {
|
public function __construct($prefix = '') {
|
||||||
@ -30,8 +30,9 @@ class Cache_XCache
|
|||||||
public function get($key)
|
public function get($key)
|
||||||
{
|
{
|
||||||
$tmp = '';
|
$tmp = '';
|
||||||
if($this->fetch($this->prefix . $key, $tmp))
|
if($this->fetch($this->prefix . $key, $tmp)) {
|
||||||
return $tmp;
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -39,8 +40,9 @@ class Cache_XCache
|
|||||||
public function fetch($key, &$var)
|
public function fetch($key, &$var)
|
||||||
{
|
{
|
||||||
$key = $this->prefix . $key;
|
$key = $this->prefix . $key;
|
||||||
if(!xcache_isset($key))
|
if(!xcache_isset($key)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$var = xcache_get($key);
|
$var = xcache_get($key);
|
||||||
return true;
|
return true;
|
||||||
@ -54,4 +56,3 @@ class Cache_XCache
|
|||||||
return $this->enabled;
|
return $this->enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user