mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00
* php 7.x APCu cache support
This commit is contained in:
parent
a95c93cd5b
commit
c415cf5ffb
1
TODO
1
TODO
@ -6,6 +6,7 @@
|
|||||||
* sandbox for plugins, don't install when requirements are not passed
|
* sandbox for plugins, don't install when requirements are not passed
|
||||||
* load items & weapons on install, preferably with ajax
|
* load items & weapons on install, preferably with ajax
|
||||||
* add changelog management interface
|
* add changelog management interface
|
||||||
|
* option to require php extension to be installed
|
||||||
|
|
||||||
1.0:
|
1.0:
|
||||||
* i18n support (issue #1 on github)
|
* i18n support (issue #1 on github)
|
||||||
|
@ -56,7 +56,7 @@ $config = array(
|
|||||||
'views_counter' => true,
|
'views_counter' => true,
|
||||||
|
|
||||||
// cache system. by default file cache is used
|
// cache system. by default file cache is used
|
||||||
'cache_engine' => 'auto', // apc, eaccelerator, xcache, file, auto, or blank to disable.
|
'cache_engine' => 'auto', // apc, apcu, eaccelerator, xcache, file, auto, or blank to disable.
|
||||||
'cache_prefix' => 'myaac_', // have to be unique if running more MyAAC instances on the same server (except file system cache)
|
'cache_prefix' => 'myaac_', // have to be unique if running more MyAAC instances on the same server (except file system cache)
|
||||||
|
|
||||||
// database details (leave blank for auto detect from config.lua)
|
// database details (leave blank for auto detect from config.lua)
|
||||||
|
@ -23,6 +23,11 @@ class Cache
|
|||||||
self::$instance = new Cache_APC($prefix);
|
self::$instance = new Cache_APC($prefix);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'apcu':
|
||||||
|
require('cache_apcu.php');
|
||||||
|
self::$instance = new Cache_APCu($prefix);
|
||||||
|
break;
|
||||||
|
|
||||||
case 'eaccelerator':
|
case 'eaccelerator':
|
||||||
require('cache_eaccelerator.php');
|
require('cache_eaccelerator.php');
|
||||||
self::$instance = new Cache_eAccelerator($prefix);
|
self::$instance = new Cache_eAccelerator($prefix);
|
||||||
@ -55,6 +60,8 @@ class Cache
|
|||||||
{
|
{
|
||||||
if(function_exists('apc_fetch'))
|
if(function_exists('apc_fetch'))
|
||||||
return 'apc';
|
return 'apc';
|
||||||
|
else if(function_exists('apcu_fetch'))
|
||||||
|
return 'apcu';
|
||||||
else if(function_exists('eaccelerator_get'))
|
else if(function_exists('eaccelerator_get'))
|
||||||
return 'eaccelerator';
|
return 'eaccelerator';
|
||||||
else if(function_exists('xcache_get') && ini_get('xcache.var_size'))
|
else if(function_exists('xcache_get') && ini_get('xcache.var_size'))
|
||||||
|
52
system/libs/cache_apcu.php
Normal file
52
system/libs/cache_apcu.php
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Cache APC class
|
||||||
|
*
|
||||||
|
* @package MyAAC
|
||||||
|
* @author Slawkens <slawkens@gmail.com>
|
||||||
|
* @author Mark Samman (Talaturen) <marksamman@gmail.com>
|
||||||
|
* @copyright 2017 MyAAC
|
||||||
|
* @link http://my-aac.org
|
||||||
|
*/
|
||||||
|
defined('MYAAC') or die('Direct access not allowed!');
|
||||||
|
|
||||||
|
class Cache_APCu
|
||||||
|
{
|
||||||
|
private $prefix = '';
|
||||||
|
private $enabled;
|
||||||
|
|
||||||
|
public function __construct($prefix = '')
|
||||||
|
{
|
||||||
|
$this->prefix = $prefix;
|
||||||
|
$this->enabled = function_exists('apcu_fetch');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function set($key, $var, $ttl = 0)
|
||||||
|
{
|
||||||
|
$key = $this->prefix . $key;
|
||||||
|
apcu_delete($key);
|
||||||
|
apcu_store($key, $var, $ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($key)
|
||||||
|
{
|
||||||
|
$tmp = '';
|
||||||
|
if($this->fetch($key, $tmp))
|
||||||
|
return $tmp;
|
||||||
|
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch($key, &$var) {
|
||||||
|
return ($var = apcu_fetch($this->prefix . $key)) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete($key) {
|
||||||
|
apcu_delete($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function enabled() {
|
||||||
|
return $this->enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user