public function save($keyName = NULL, $content = NULL, $lifetime = NULL, $stopBuffer = true) { try { parent::save($keyName, $content, $lifetime, $stopBuffer); } catch (\Phalcon\Exception $e) { } }
/** * Checks if cache exists and it hasn't expired * * @param string|null $keyName * @param int|null $lifetime * @return boolean * @throws Exception */ public function exists($keyName = null, $lifetime = null) { /* Type check */ if (is_null($keyName) === true) { $keyName = $this->_lastKey; } elseif (is_string($keyName) === true) { $keyName = $this->_prefix . $keyName; } else { throw new Exception('Invalid parameter type.'); } if (is_null($lifetime) === false && is_int($lifetime) === false) { throw new Exception('Invalid parameter type.'); } /* Check for key */ if (isset($keyName) === true) { if (is_object($this->_memcache) === false) { $this->_connect(); } if ($this->_memcache->get($keyName) !== false) { return true; } } return false; }
/** * Stores cached content * * @param string $keyName * @param string $content * @param int $lifetime * @param boolean $stopBuffer */ public function set($keyName = null, $content = null, $lifetime = null, $stopBuffer = null) { if ($this->cache_status) { $this->cache->save($keyName, $content, $lifetime, $stopBuffer); } }
public function output(UnitTester $I) { $I->wantTo('Cache output fragments by using Memcache as cache backend'); $time = date('H:i:s'); $cache = new Memcache(new Output(['lifetime' => 2]), ['host' => TEST_MC_HOST, 'port' => TEST_MC_PORT]); ob_start(); // First time cache $content = $cache->start('test-output'); $I->assertNull($content); echo $time; $cache->save(null, null, null, true); $obContent = ob_get_contents(); ob_end_clean(); $I->assertEquals($time, $obContent); $I->seeInMemcached('test-output', $time); // Expect same cache $content = $cache->start('test-output'); $I->assertNotNull($content); $I->assertEquals($time, $obContent); $I->seeInMemcached('test-output', $time); sleep(2); $content = $cache->start('test-output'); $I->assertNull($content); $I->dontSeeInMemcached('test-output'); $I->clearMemcache(); }