本文整理汇总了PHP中Cache::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::save方法的具体用法?PHP Cache::save怎么用?PHP Cache::save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: end
/**
* Stops and saves the cache.
* @param array dependencies
* @return void
*/
public function end(array $dp = NULL)
{
if ($this->cache === NULL) {
throw new InvalidStateException('Output cache has already been saved.');
}
$this->cache->save($this->key, ob_get_flush(), (array) $dp + (array) $this->dependencies);
$this->cache = NULL;
}
示例2: testSave
/**
* @covers Phossa\Config\Env\Environment::save()
* @covers Phossa\Config\Env\Environment::get()
* @covers Phossa\Config\Env\Environment::clear()
*/
public function testSave()
{
$data = ['db' => ['dsn' => 'bingo']];
$this->object->save($data);
$this->assertEquals($data, $this->object->get());
$this->object->clear();
$this->assertFalse($this->object->get());
}
示例3: create
/**
* Creates accessor for instances of given class.
* @param string $class
* @return Accessor
*/
public function create($class)
{
$name = $this->naming->deriveClassName($class);
$namespaced = $this->naming->getNamespace() . '\\' . $name;
if (class_exists($namespaced) || $this->cache && $this->cache->load($name)) {
return new $namespaced();
}
$definition = $this->generator->generate($class);
if ($this->cache) {
$this->cache->save($name, $definition);
}
eval($definition);
return new $namespaced();
}
示例4: fetchData
/**
* Fetch data.
*
* @param string $path
* @param array $params
* @param string $tag
* @param int $cacheLifetime
* @param bool $forceFetch
* @return array|mixed
*/
public function fetchData($path, $params = [], $tag = '', $cacheLifetime = 0, $forceFetch = false)
{
// Set default values.
$this->code = 200;
$this->message = '';
$fetch = true;
$data = Cache::load($this->prefix, $path, $params, $cacheLifetime);
if (!$forceFetch && count($data) > 0) {
$fetch = false;
}
if ($fetch) {
// Build and request data.
$this->url = $this->buildUrl($path, $params);
try {
$client = new \GuzzleHttp\Client();
$result = $client->get($this->url);
if ($result->getStatusCode() == 200) {
$data = json_decode($result->getBody(), true);
}
} catch (\Exception $e) {
$this->code = $e->getCode();
$this->message = $e->getMessage();
}
// Save cache.
if ($cacheLifetime > 0) {
Cache::save($this->prefix, $path, $params, $data);
}
}
// Extract on tag.
if ($tag != '' && isset($data[$tag])) {
$data = $data[$tag];
}
return $data;
}
示例5: render
/**
* Renders template to output.
* @return void
*/
public function render()
{
if ($this->file == NULL) {
// intentionally ==
throw new InvalidStateException("Template file name was not specified.");
}
$this->__set('template', $this);
$shortName = str_replace(Environment::getVariable('appDir'), '', $this->file);
$cache = new Cache($this->getCacheStorage(), 'Nette.Template');
$key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file);
$cached = $content = $cache[$key];
if ($content === NULL) {
if (!$this->getFilters()) {
$this->onPrepareFilters($this);
}
if (!$this->getFilters()) {
LimitedScope::load($this->file, $this->getParams());
return;
}
$content = $this->compile(file_get_contents($this->file), "file …{$shortName}");
$cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire));
$cache->release();
$cached = $cache[$key];
}
if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) {
LimitedScope::load($cached['file'], $this->getParams());
fclose($cached['handle']);
} else {
LimitedScope::evaluate($content, $this->getParams());
}
}
示例6: render
/**
* Renders template to output.
* @return void
*/
public function render()
{
if ($this->file == NULL) {
// intentionally ==
throw new InvalidStateException("Template file name was not specified.");
}
$cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
if ($storage instanceof PhpFileStorage) {
$storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file);
}
$cached = $compiled = $cache->load($this->file);
if ($compiled === NULL) {
try {
$compiled = "<?php\n\n// source file: {$this->file}\n\n?>" . $this->compile();
} catch (TemplateException $e) {
$e->setSourceFile($this->file);
throw $e;
}
$cache->save($this->file, $compiled, array(Cache::FILES => $this->file, Cache::CONSTS => 'Framework::REVISION'));
$cached = $cache->load($this->file);
}
if ($cached !== NULL && $storage instanceof PhpFileStorage) {
LimitedScope::load($cached['file'], $this->getParameters());
} else {
LimitedScope::evaluate($compiled, $this->getParameters());
}
}
示例7: loadFromID
public function loadFromID($id, $loadmeta = true, $loadelements = true)
{
// Loads content with given ID
$cachekey = "content:id:" . $id;
$content = Cache::load($cachekey);
if (!isset($content['id'])) {
// No cache found, load from database
$sql = new SqlManager();
// ...here server and language (both coming from controller if available) should be included!
$sql->setQuery("SELECT * FROM content WHERE id={{id}}");
$sql->bindParam("{{id}}", $id, "int");
$content = $sql->result();
if (!isset($content['id'])) {
throw new Exception("No content for ID '{$id}' found!");
return false;
}
$this->id = $content['id'];
$this->data = $content;
// Load other content data as well
if ($loadmeta) {
$this->data['meta'] = $this->loadMeta();
}
if ($loadelements) {
$this->data['elements'] = $this->loadElements();
}
// Save cache for later
Cache::save($cachekey, $this->data);
Cache::save("content:url:" . $this->data['url'], $this->data);
}
return true;
}
示例8: processCache
public function processCache($params)
{
if ($this->getOption("cacheEnabled")) {
// check the database for cache
$c = new Cache($this);
$cacheId = $this->getCacheId($params);
// check whether cache is valid, and if so, retrieve content
// from the cache. Content is loaded into the cache with
// this call.
if ($c->isValid($cacheId)) {
// parse cache content back from string to suitable object with
// deformatCacheContent method different for every request type
$this->setResult(true, $this->deformatCacheContent($c->getContent()));
} else {
// execute request like it would if there was no cache
$this->parseRequest($params);
// format result into string for db storage
$cacheContent = $this->formatCacheContent($this->result);
// save formatted result to cache
$c->save($cacheId, $cacheContent);
}
} else {
// caching is not enabled, just parse the request
$this->parseRequest($params);
}
}
示例9: load
public function load()
{
// Load config
// Try from cache
$cachekey = "config";
if ($this->user) {
$cachekey .= ":" . $this->user;
}
$this->config = Cache::load("config");
if (!is_array($this->config) || $this->get('cache.active') != 1) {
// Load config from database
$sql = new SqlManager();
if (!is_null($this->user)) {
$sql->setQuery("SELECT * FROM config WHERE user_id = {{user}}");
$sql->bindParam("{{user}}", $this->user);
} else {
$sql->setQuery("SELECT * FROM config WHERE user_id IS NULL");
}
$sql->execute();
$this->config = array();
while ($row = $sql->fetch()) {
$this->config[$row['name']] = $row['value'];
}
if (!isset($this->config['cache.active']) || $this->config['cache.active'] != 1) {
// If cache is deactivated, clear possible cache file
Cache::clear($cachekey);
} else {
// If cache is activeated, save config for later use
Cache::save($cachekey, $this->config);
}
}
}
示例10: _verifySign
private function _verifySign($domain, $text, $sign)
{
include_once KFL_DIR . '/Libs/Cache.class.php';
$filename = $domain . ".txt";
$cache = new Cache(86400 * 300, 0);
$cache->setCacheStore("file");
// or memcache
$cache->setCacheDir(APP_TEMP_DIR);
$cache->setCacheFile($filename);
if ($cache->isCached()) {
$client = unserialize($cache->fetch());
} else {
require_once 'ClientModel.class.php';
$ClientModel = new ClientModel();
$client = $ClientModel->getClientByName($domain);
if ($client) {
$cache->save(serialize($client));
} else {
return false;
}
}
$this->_private_key = $client['private_key'];
if (hmac($this->_private_key, $text, 'sha1') == $sign) {
return true;
} else {
return false;
}
}
示例11: testSaveWithTTL
public function testSaveWithTTL()
{
$value = 'a string value';
$redis = $this->getMockBuilder('\\Redis')->getMock();
$redis->expects($this->once())->method('setex')->with('prefix:key', 200, serialize($value))->willReturn(true);
$cache = new Cache($redis, 'prefix');
$this->assertTrue($cache->save('key', $value, 200));
}
示例12: setObject
/**
* @param string $key
* @param mixed $val
* @return Cache
*/
public static function setObject($key, $val)
{
$cache = new Cache();
$cache->id = $key;
$cache->daten = serialize($val);
$cache->datum = new CDbExpression('NOW()');
$cache->save();
return $cache;
}
示例13: getTree
public static function getTree($name, $levels = 1)
{
$cachekey = "assortment:tree:" . $name;
$assortment = Cache::load($cachekey);
if (!is_array($assortment)) {
$assortment = self::load($name, null, 0, $levels);
Cache::save($cachekey, $assortment);
}
return $assortment;
}
示例14: acquire
/**
* Acquire the key or refresh a lock.
*
* @param string $key Key that should fit the lock when refreshing the lock.
* @return string|false
*/
public function acquire($key = null)
{
if ($this->getKey() && $key != $this->getKey()) {
return false;
}
if (!isset($key)) {
$key = md5(microtime());
}
$this->info = array('timestamp' => strftime('%Y-%m-%d %T'), 'key' => $key);
if (class_exists('Q\\Auth', false) && Auth::i()->isLoggedIn()) {
$this->info['user'] = Auth::i()->user()->getUsername();
$this->info['user_fullname'] = Auth::i()->user()->getFullaname();
}
if (!$this->store instanceof Cache) {
$this->store = Cache::with($this->store);
}
$this->store->save('lock:' . $this->name, $this->info, $this->timeout);
return $key;
}
示例15: callback
/**
* Callback for output handling.
*
* @param string|array $buffer
* @param int $flags
* @return string|array
*/
public function callback($buffer, $flags)
{
if (is_array($buffer)) {
$this->data = $buffer;
} else {
$marker = Output::curMarker();
if ($marker !== null) {
if (!is_array($this->data)) {
$this->data = isset($this->data) ? array(Output::$defaultMarker => $this->data) : array();
}
$this->data[$marker] = $this->data;
} else {
$this->data .= $buffer;
}
}
if ($flags & PHP_OUTPUT_HANDLER_END) {
$this->cache->save(static::makeKey(), $this->data);
}
return false;
}