Author: Nick Sagona, III (dev@nolainteractive.com)
コード例 #1
0
ファイル: MemcachedTest.php プロジェクト: nicksagona/PopPHP
 public function testGetVersion()
 {
     if (class_exists('Memcache')) {
         $c = Cache::factory(new Memcached(), 30);
         $this->assertNotNull($c->adapter()->getVersion());
     }
 }
コード例 #2
0
ファイル: ApcTest.php プロジェクト: nicksagona/PopPHP
 public function testGetInfo()
 {
     if (function_exists('apc_add')) {
         $c = Cache::factory(new Apc(), 30);
         $this->assertTrue(is_array($c->adapter()->getInfo()));
     }
 }
コード例 #3
0
ファイル: CacheTest.php プロジェクト: nicksagona/PopPHP
 public function testSaveAndLoad()
 {
     if (!file_exists(__DIR__ . '/../tmp/cache')) {
         mkdir(__DIR__ . '/../tmp/cache');
         chmod(__DIR__ . '/../tmp/cache', 0777);
     }
     $str = 'This is my test variable. It contains a string.';
     $c = Cache::factory(new File(__DIR__ . '/../tmp/cache'), 30);
     $this->fileExists($c->adapter()->getDir());
     $c->save('str', $str);
     $this->assertEquals($str, $c->load('str'));
     $c->remove('str');
     $c->clear();
     if (file_exists(__DIR__ . '/../tmp/cache')) {
         rmdir(__DIR__ . '/../tmp/cache');
     }
 }
コード例 #4
0
ファイル: Cache.php プロジェクト: phirecms/phire-cache
 /**
  * Get cache config
  *
  * @return array
  */
 public function getConfig()
 {
     $status = Table\Config::findById('cache_status');
     $adapter = Table\Config::findById('cache_adapter');
     $lifetime = Table\Config::findById('cache_lifetime');
     $adapters = [];
     $cacheAdapters = \Pop\Cache\Cache::getAvailableAdapters();
     foreach ($cacheAdapters as $adapt => $avail) {
         if ($adapt !== 'file' && $avail) {
             $adapters[ucwords($adapt)] = ucwords($adapt);
         }
     }
     if (isset($lifetime->value)) {
         $cacheStatus = (int) $status->value;
         $cacheLifetime = $lifetime->value;
         // Days
         if ($cacheLifetime >= 86400) {
             $cacheLifetimeValue = round($cacheLifetime / 86400, 1);
             $cacheLifetimeUnit = 'Days';
             // Hours
         } else {
             if ($cacheLifetime < 86400 && $cacheLifetime >= 3600) {
                 $cacheLifetimeValue = round($cacheLifetime / 3600, 1);
                 $cacheLifetimeUnit = 'Hours';
                 // Minutes
             } else {
                 $cacheLifetimeValue = round($cacheLifetime / 60, 1);
                 $cacheLifetimeUnit = 'Minutes';
             }
         }
     } else {
         $cacheStatus = 0;
         $cacheLifetime = 0;
         $cacheLifetimeValue = 0;
         $cacheLifetimeUnit = null;
     }
     $config = ['cache_status' => $cacheStatus, 'cache_adapter' => isset($adapter->value) ? $adapter->value : null, 'cache_lifetime' => $cacheLifetime, 'cache_lifetime_value' => $cacheLifetimeValue, 'cache_lifetime_unit' => $cacheLifetimeUnit, 'cache_adapters' => $adapters];
     return $config;
 }
コード例 #5
0
ファイル: cache2.php プロジェクト: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Cache;
try {
    $cache = Cache\Cache::factory(new Cache\Adapter\File('../tmp'), 30);
    //$cache = Cache\Cache::factory(new Cache\Adapter\Memcached(), 30);
    //$cache = Cache\Cache::factory(new Cache\Adapter\Sqlite('../tmp/cache.sqlite'), 30);
    //$cache = Cache\Cache::factory(new Cache\Adapter\Apc(), 30);
    if (!($var = $cache->load('test'))) {
        echo 'It\'s either not there or expired.';
    } else {
        echo $var;
    }
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
コード例 #6
0
ファイル: SqliteTest.php プロジェクト: nicksagona/PopPHP
 public function testDelete()
 {
     $c = Cache::factory(new Sqlite(__DIR__ . '/../tmp/cache.sqlite'), 30);
     $c->adapter()->delete();
     $this->assertFalse(file_exists(__DIR__ . '/../tmp/cache.sqlite'));
 }