本文整理汇总了PHP中Cache::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::load方法的具体用法?PHP Cache::load怎么用?PHP Cache::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cache
的用法示例。
在下文中一共展示了Cache::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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());
}
}
示例2: setConnection
public function setConnection(Connection $connection)
{
$this->connection = $connection;
if ($this->cacheStorage) {
$this->cache = new Cache($this->cacheStorage, 'Nette.Database.' . md5($connection->getDsn()));
$this->structure = ($tmp = $this->cache->load('structure')) ? $tmp : $this->structure;
}
}
示例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: render
/**
* Renders template to output.
* @return void
*/
public function render()
{
$cache = new Cache($storage = $this->getCacheStorage(), 'Nette.Template');
$cached = $compiled = $cache->load($this->source);
if ($compiled === NULL) {
$compiled = $this->compile();
$cache->save($this->source, $compiled, array(Cache::CONSTS => 'Framework::REVISION'));
$cached = $cache->load($this->source);
}
if ($cached !== NULL && $storage instanceof PhpFileStorage) {
LimitedScope::load($cached['file'], $this->getParameters());
} else {
LimitedScope::evaluate($compiled, $this->getParameters());
}
}
示例5: get_content
public function get_content()
{
$metric = $this->get_metric();
$metric = Cache::load($this, 300);
//5 minute cache for disk io
$disk_io = array(array('Disk', 'Read(MB)', 'Write(MB)'));
foreach ($metric['disk'] as $disk => $stat) {
$disk_io[] = array($disk, $stat['read'], $stat['write']);
}
$disk_io = json_encode($disk_io);
$cpu_io = json_encode(array(array('CPU Time', 'Percent'), array('IO Wait', $metric['cpu']['io_wait'])));
echo <<<EOD
<div id="widget_disk_io"></div>
<div id="widget_cpu_io_wait"></div>
<script type="text/javascript">
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(function () {
var data = google.visualization.arrayToDataTable({$cpu_io});
var goptions = {
redFrom: 90, redTo: 100,
yellowFrom:75, yellowTo: 90,
minorTicks: 5
};
var chart = new google.visualization.Gauge(document.getElementById('widget_cpu_io_wait'));
chart.draw(data, goptions);
var data2 = google.visualization.arrayToDataTable({$disk_io});
var chart2 = new google.visualization.ColumnChart(document.getElementById('widget_disk_io'));
chart2.draw(data2, {});
})
</script>
EOD;
}
示例6: 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;
}
示例7: get_content
public function get_content()
{
$metric = $this->get_metric();
$metric = Cache::load($this, 300);
$data = array(array('Type', 'Used(MB)', 'Free(MB)'));
foreach ($metric as $item) {
if (empty($item)) {
continue;
}
if ($item['type'] !== 'Mem' && $item['type'] !== 'Swap') {
continue;
}
if (0 == $item['free'] + $item['used']) {
continue;
}
$data[] = array($item['type'], $item['used'], $item['free']);
}
$data = json_encode($data);
echo <<<EOD
<div id="widget_ram_usage"></div>
<script type="text/javascript">
google.setOnLoadCallback(function () {
var data = google.visualization.arrayToDataTable({$data});
var options = {
isStacked: true
};
var chart = new google.visualization.ColumnChart(document.getElementById('widget_ram_usage'));
chart.draw(data, options);
})
</script>
EOD;
}
示例8: _get_cats_tree
function _get_cats_tree()
{
global $LANG, $CAT_ARTICLES;
Cache::load('articles');
if (!(isset($CAT_ARTICLES) && is_array($CAT_ARTICLES))) {
$CAT_ARTICLES = array();
}
$ordered_cats = array();
foreach ($CAT_ARTICLES as $id => $cat) {
$cat['id'] = $id;
$ordered_cats[numeric($cat['id_left'])] = array('this' => $cat, 'children' => array());
}
$level = 0;
$cats_tree = array(array('this' => array('id' => 0, 'name' => $LANG['root']), 'children' => array()));
$parent =& $cats_tree[0]['children'];
$nb_cats = count($CAT_ARTICLES);
foreach ($ordered_cats as $cat) {
if ($cat['this']['level'] == $level + 1 && count($parent) > 0) {
$parent =& $parent[count($parent) - 1]['children'];
} elseif ($cat['this']['level'] < $level) {
$j = 0;
$parent =& $cats_tree[0]['children'];
while ($j < $cat['this']['level']) {
$parent =& $parent[count($parent) - 1]['children'];
$j++;
}
}
$parent[] = $cat;
$level = $cat['this']['level'];
}
return $cats_tree[0];
}
示例9: 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;
}
示例10: 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);
}
}
}
示例11: getURLContents
/**
*
*/
protected function getURLContents()
{
if (isset($this->cache) && !$this->refresh) {
$contents = $this->cache->load('URLContents', $loaded);
if ($loaded) {
return $contents;
}
}
$contents = $this->request->init()->process();
if ($contents === FALSE) {
throw new Exception('URL konnte nicht gelesen werden: ' . Code::varInfo($this->request->getURL()));
}
if (isset($this->cache)) {
$this->cache->store('URLContents', $contents);
}
return $contents;
}
示例12: get_content
public function get_content()
{
$cmds = Cache::load($this, 3600 * 24);
$content = '';
foreach ($cmds as $cmd => $info) {
$content .= "<p><strong>{$cmd}</strong> {$info}</p>";
}
echo $content;
}
示例13: get_jsapi_ticket
public function get_jsapi_ticket()
{
$cache = new Cache();
$TICKET = $cache->load('TICKET');
if (empty($TICKET)) {
$result = json_decode($this->send_post('v=v', 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $this->get_token() . '&type=jsapi'));
$cache->save('TICKET', $result->ticket, 7200);
}
return $cache->load('TICKET');
}
示例14: 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;
}
示例15: testLoadInvalidValueAtKey
public function testLoadInvalidValueAtKey()
{
$redis1 = $this->getMockBuilder('\\Redis')->getMock();
$redis1->method('get')->willReturn(false);
$cache1 = new Cache($redis1, 'prefix');
$this->assertEquals(false, $cache1->load('unchecked:key'));
$redis2 = $this->getMockBuilder('\\Redis')->getMock();
$redis2->method('get')->willReturn([]);
$cache2 = new Cache($redis1, 'prefix');
$this->assertEquals(false, $cache2->load('unchecked:key'));
}