Example #1
0
 public function get(UnitTester $I)
 {
     $I->wantTo('Get data by using Memcache as cache backend');
     $key = 'data-get';
     $data = [uniqid(), gethostname(), microtime(), get_include_path(), time()];
     $cache = new Memcache(new Data(['lifetime' => 20]), ['host' => TEST_MC_HOST, 'port' => TEST_MC_PORT]);
     $I->haveInMemcached($key, serialize($data));
     $I->assertEquals($data, $cache->get('data-get'));
     $I->assertNull($cache->get('non-existent-key'));
     $data = 'sure, nothing interesting';
     $I->haveInMemcached($key, serialize($data));
     $I->assertEquals($data, $cache->get('data-get'));
     $I->assertNull($cache->get('non-existent-key-2'));
     $I->clearMemcache();
 }
Example #2
0
 /**
  * Returns a cached content
  *
  * @param string $keyName
  * @param int $lifetime
  * @return mixed
  */
 public function get($keyName, $lifetime = null)
 {
     if ($this->cache_status) {
         return $this->cache->get($keyName, $lifetime);
     } else {
         return null;
     }
 }