/**
  * Function to call other class within XCCache
  * 
  * @param type $date
  * @return type
  */
 public function otherClassCache($date)
 {
     // xcache MUST TO BE ASSIGNED TO A CLASS
     $newclass = new OtherClassCache();
     $XCache = XCache::getXCInstance();
     return $XCache->cache('cache_test', 'MyExternallClassCall', 'otherClass', get_class($newclass), 'otherMethod', $date);
 }
Пример #2
0
 /**
  * getXCInstance
  * 
  * Return current intance of XCache
  * 
  * @return object
  */
 public static function getXCInstance()
 {
     if (!isset(self::$xcinstance)) {
         self::$xcinstance = new self();
     }
     return self::$xcinstance;
 }
Пример #3
0
        if (!count($MCache->getServerList())) {
            $MCache->addServer(MemCacheHost, MemCachePort);
        }
    } elseif (extension_loaded('memcache')) {
        //MemCache
        require __DIR__ . "/includes/MemcacheMod.class.php";
        $MCache = new MemcacheMod(MemCacheHost, MemCachePort);
    } elseif (extension_loaded('redis')) {
        //Redis
        //https://github.com/phpredis/phpredis
        $MCache = new Redis();
        $MCache->pconnect(MemCacheHost, MemCachePort);
    } elseif (extension_loaded('xcache')) {
        // XCache
        require __DIR__ . "/includes/XCache.class.php";
        $MCache = new XCache();
    }
}
//Load configuration
$Config = array();
if ($MCache) {
    $Config = $MCache->get(MemCachePrefix . 'Config');
}
if (!$Config) {
    foreach ($DB->query('SELECT ConfigName,ConfigValue FROM ' . $Prefix . 'config') as $ConfigArray) {
        $Config[$ConfigArray['ConfigName']] = $ConfigArray['ConfigValue'];
    }
    // Update
    if ($Config['Version'] != CARBON_FORUM_VERSION) {
        header("Location: update/");
        // Bring user to installation
Пример #4
0
<?php

// Define the xcacheconf configuration location
define("XCACHE_CONFPATH", __DIR__);
define("HTMLCODE_BR", php_sapi_name() == 'cli' ? "\n" : "<br>");
define("HTMLCODE_HR", php_sapi_name() == 'cli' ? "\n----------------------------------------------------------\n" : "<hr>");
// Include composer autoload
include_once "../../../../../vendor/autoload.php";
$XCache = new XCache();
$XCache->setCacheHeaders();
if ($XCache->enableCache()) {
    echo HTMLCODE_HR . "PAGE OBTAINED FROM CACHE" . HTMLCODE_HR;
    die;
}
class TestPageCache
{
    public function getPage()
    {
        $page = file_get_contents('http://www.php.net/');
        return $page;
    }
}
$test = new TestPageCache();
echo $test->getPage();
$XCache->writeAndFlushCache();
echo HTMLCODE_HR . "PAGE CACHED NOW" . HTMLCODE_HR;
Пример #5
0
 /**
  * check if there is a in-server backend available
  *
  * @return bool
  */
 public static function isAvailableLowLatency()
 {
     return XCache::isAvailable() || APCu::isAvailable() || APC::isAvailable();
 }
Пример #6
0
 /**
  * @requires extension xcache
  */
 function testCache()
 {
     $cache = new XCache();
     $users = ['Masoud', 'Alireza'];
     $cache->write('users', $users);
     $this->assertCount(1, $cache->stats());
     $this->assertTrue($cache->contains('users'));
     $this->assertEquals($users, $cache->read('users'));
     $this->assertFalse($cache->expired('users', 1));
     $i = 0;
     $posts = ['Post 1', 'Post 2'];
     for ($j = 0; $j < 10; $j++) {
         $result = $cache->remember('posts', function () use(&$i, $posts) {
             $i++;
             return $posts;
         }, 10);
     }
     $this->assertEquals(1, $i);
     $this->assertEquals($posts, $result);
     $this->assertEquals($posts, $cache->read('posts'));
     $this->assertCount(2, $cache->stats());
     $cache->delete('users');
     $this->assertFalse($cache->contains('users'));
     $this->assertTrue($cache->contains('posts'));
     $cache->deleteAll();
     $this->assertCount(0, $cache->stats());
 }