factory() public static method

Static method to instantiate the cache object and return itself to facilitate chaining methods together.
public static factory ( Pop\Cache\Adapter\AdapterInterface $adapter, integer $lifetime ) : Cache
$adapter Pop\Cache\Adapter\AdapterInterface
$lifetime integer
return Cache
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
<?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. 5
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'));
 }