Author: Nick Sagona, III (dev@nolainteractive.com)
Esempio n. 1
0
 public function testGetVersion()
 {
     if (class_exists('Memcache')) {
         $c = Cache::factory(new Memcached(), 30);
         $this->assertNotNull($c->adapter()->getVersion());
     }
 }
Esempio n. 2
0
 public function testGetInfo()
 {
     if (function_exists('apc_add')) {
         $c = Cache::factory(new Apc(), 30);
         $this->assertTrue(is_array($c->adapter()->getInfo()));
     }
 }
Esempio n. 3
0
 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');
     }
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
<?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;
}
Esempio n. 6
0
 public function testDelete()
 {
     $c = Cache::factory(new Sqlite(__DIR__ . '/../tmp/cache.sqlite'), 30);
     $c->adapter()->delete();
     $this->assertFalse(file_exists(__DIR__ . '/../tmp/cache.sqlite'));
 }