/** * 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()); } }
/** * Load response from cache * * @return \Magento\Framework\App\Response\Http|false */ public function load() { if ($this->request->isGet() || $this->request->isHead()) { return unserialize($this->cache->load($this->identifier->getValue())); } return false; }
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; } }
/** * 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(); }
/** * 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()); } }
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; }
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; }
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; }
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]; }
/** * 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; }
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); } } }
/** * */ 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; }
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; }
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'); }
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; }
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')); }
public function get_content() { $interfaces = Cache::load($this, 300); $html = '<table class="wp-list-table widefat"><thead><tr> <th>Interface</th> <th>IP</th> </tr></thead><tbody>'; foreach ($interfaces as $interface => $ip) { $html .= "<tr>\n <td>{$interface}</td>\n <td>{$ip}</td>\n </tr>"; } $html .= '</tbody></table>'; echo $html; }
public function get_content() { $metric = $this->get_metric(); $metric = Cache::load($this, 60 * 10); //Cache disk usage for 10 minutes $data = array(array('Disk', 'Space')); $disk_container = array(); $data_partition = array(array('Filesystem', 'Free(GB)', 'Used(GB)')); foreach ($metric as $disk) { $size = intval($disk['size']); if ('M' == substr($disk['size'], -1)) { $size = round($size / 1024, 2); } $used = intval($disk['used']); if ('M' == substr($disk['used'], -1)) { $used = round($used / 1024, 2); } if (empty($size)) { continue; } $data[] = array($disk['filesystem'], $size); $data_partition[] = array($disk['filesystem'], $size - $used, $used); } $data = json_encode($data); $data_partition = json_encode($data_partition); echo <<<EOD <div id="widget_disk_usage"></div> <div id="widget_disk_partion"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(function () { var data = google.visualization.arrayToDataTable({$data}); var options = { is3D: true, }; var chart = new google.visualization.PieChart(document.getElementById('widget_disk_usage')); chart.draw(data, options); var data2 = google.visualization.arrayToDataTable({$data_partition}); var options2 = { isStacked: true }; var chart2 = new google.visualization.ColumnChart(document.getElementById('widget_disk_partion')); chart2.draw(data2, options2); }) </script> EOD; }
public function parse() { if (!file_exists($this->file)) { throw new NotFound("Template {$this->file} does not exist"); } if ($this->load_from_cache) { $oCache = new Cache($this->tpl); if ($oCache->isValid()) { return $oCache->load(); } else { $content = $this->readTemplate(); $oCache->cache($content); return $content; } } return $this->readTemplate(); }
/** * Gets a list of links * * @return \Storyblok\Client */ public function getLinks() { $version = 'published'; if ($this->editModeEnabled) { $version = 'draft'; } if ($version == 'published' && $this->cache && ($cachedItem = $this->cache->load($this->linksPath))) { $this->responseBody = (array) $cachedItem; } else { $options = array('token' => $this->apiKey, 'version' => $version); $response = $this->get($this->linksPath, $options); $this->responseBody = $response->httpResponseBody; if ($this->cache && $version == 'published') { $this->cache->save($this->responseBody, $this->linksPath); } } return $this; }
public static function loadVersions($type, $id) { $versions = Cache::load("version:" . $type . ":" . $id); if (!is_array($versions)) { $sql = new SqlManager(); $sql->setQuery("\n\t\t\t\tSELECT id, date FROM version\n\t\t\t\tWHERE object_table = '{{type}}'\n\t\t\t\t\tAND object_id = {{id}}\n\t\t\t\t\tAND draft IS NULL\n\t\t\t\tORDER BY date ASC\n\t\t\t\t"); $sql->bindParam("{{type}}", $type); $sql->bindParam("{{id}}", $id, "int"); $sql->execute(); $versions = array("_index" => array()); while ($row = $sql->fetch()) { $versions['_index'][] = $row['id']; $versions[$row['id']] = $row; } Cache::save("version:" . $type . ":" . $id, $versions); } return $versions; }
/** * @return \Components\Runtime */ public static function create() { if (null === self::$m_instance) { self::$m_instance = new self(); self::$m_isCli = 'cli' === PHP_SAPI; set_error_handler([self::$m_instance, 'onError'], error_reporting()); set_exception_handler([self::$m_instance, 'onException']); self::$m_cacheFile = sys_get_temp_dir() . DIRECTORY_SEPARATOR . COMPONENTS_INSTANCE_CODE . '.cache'; register_shutdown_function([self::$m_instance, 'onExit']); if (self::$m_isCli) { if (@is_file(self::$m_cacheFile)) { Cache::load(self::$m_cacheFile); } } self::$m_version = new Version(COMPONENTS_RUNTIME_VERSION_MAJOR, COMPONENTS_RUNTIME_VERSION_MINOR, COMPONENTS_RUNTIME_VERSION_BUILD); Environment::includeComponentConfig('runtime'); } return self::$m_instance; }
/** * @name templatePart * This function load a file located in $appdir/public/templates/$tempalte/$file * @param string $file File to include * @param string $cat_cache Category of cache * @param string $name_cache Name of cache * @param number $tcache Time in seconds maxium lifetime cache */ static function templatePart($file, $cat_cache = null, $name_cache = null, $tcache = null) { // If it would use cache if ($name_cache) { $cat_cache = kw::ses('lang') . '/' . $cat_cache; // If not have cache (so it will not loaded) if (!Cache::load('html', $cat_cache, $name_cache, $tcache)) { // Generate it ob_start(); require kw::$app_dir . 'public/templates/' . app::$template . '/' . $file . '.php'; cache::buildFromString('html', $cat_cache, $name_cache, ob_get_contents()); // Once end, it send information to client ob_end_flush(); } } else { // No cache, load directly require kw::$app_dir . 'public/templates/' . app::$template . '/' . $file . '.php'; } }
public function get_content() { $interfaces = Cache::load($this, 300); $data = array_merge(array(array('Interface', 'Receive(package)', 'Transfer(package)')), $interfaces); $data = json_encode($data); echo <<<EOD <div id="nio_chart"></div> <script type="text/javascript"> google.setOnLoadCallback(function () { var data = google.visualization.arrayToDataTable({$data}); var options = { }; var chart = new google.visualization.ColumnChart(document.getElementById('nio_chart')); chart.draw(data, options); }) </script> EOD; }
public static function load($lang = null) { if (!$lang) { $lang = self::getLanguage(); } $cachekey = "locale:" . $lang; $locale = Cache::load($cachekey); if (!is_array($locale)) { // No cache available -> load from database $sql = new SqlManager(); $sql->setQuery("SELECT * FROM locale WHERE language = {{lang}}"); $sql->bindParam('{{lang}}', $lang, "int"); $sql->execute(); $locale = array(); while ($res = $sql->fetch()) { self::$locales[$lang][$res['code']] = $res['text']; } // Save loaded locales into cache file for later use Cache::save($cachekey, $locale); } }
function guild_list($TFSVersion) { $cache = new Cache('engine/cache/guildlist'); if ($cache->hasExpired()) { if ($TFSVersion != 'TFS_10') { $guilds = mysql_select_multi("SELECT `t`.`id`, `t`.`name`, `t`.`creationdata`, `motd`, (SELECT count(p.rank_id) FROM players AS p LEFT JOIN guild_ranks AS gr ON gr.id = p.rank_id WHERE gr.guild_id =`t`.`id`) AS `total` FROM `guilds` as `t` ORDER BY `t`.`name`;"); } else { $guilds = mysql_select_multi("SELECT `id`, `name`, `creationdata`, `motd`, (SELECT COUNT('guild_id') FROM `guild_membership` WHERE `guild_id`=`id`) AS `total` FROM `guilds` ORDER BY `name`;"); } // Add level data info to guilds if ($guilds !== false) { for ($i = 0; $i < count($guilds); $i++) { $guilds[$i]['level'] = get_guild_level_data($guilds[$i]['id']); } } $cache->setContent($guilds); $cache->save(); } else { $guilds = $cache->load(); } return $guilds; }
public function get_content() { $metrics = $this->get_metric(); $metrics = Cache::load($this, 300); //5 minute cache if (!$metrics) { return false; } // see https://google-developers.appspot.com/chart/interactive/docs/gallery/barchart#Data_Format for more detai of format $data = array(array('Duration', '% Load')); foreach ($metrics as $key => $metric) { array_push($data, array($metric[0], $metric[1])); } $data = json_encode($data); echo <<<EOD <div id="avg_load"></div> <script type="text/javascript"> google.load("visualization", "1", {packages:["corechart"]}); google.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable({$data}); var options = { hAxis: { titleTextStyle: {color: 'red'}, minValue:0, maxValue:100 } }; var chart = new google.visualization.BarChart(document.getElementById('avg_load')); chart.draw(data, options); } </script> EOD; }
// Sort $tmpPlayers by player id $tmpById = array(); foreach ($tmpPlayers as $p) { $tmpById[$p['id']] = $p['name']; } for ($i = 0; $i < count($houses); $i++) { if ($houses[$i]['owner'] > 0) { $houses[$i]['ownername'] = $tmpById[$houses[$i]['owner']]; } } } $cache->setContent($houses); $cache->save(); } } else { $houses = $cache->load(); } if ($houses !== false || !empty($houses)) { // Intialize stuff //data_dump($houses, false, "House data"); ?> <table id="housetable"> <tr class="yellow"> <th>Name</th> <th>Size</th> <th>Beds</th> <th>Rent</th> <th>Owner</th> <th>Town</th> </tr> <?php
/** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. */ protected function setUp() { global $O; $this->object = Cache::load($O); $this->O = $O; }
<div class="sidebar"> <h3>Top 5 players</h3> <?php $cache = new Cache('engine/cache/topPlayer'); if ($cache->hasExpired()) { $players = mysql_select_multi('SELECT `name`, `level`, `experience` FROM `players` WHERE `group_id` < ' . $config['highscore']['ignoreGroupId'] . ' ORDER BY `experience` DESC LIMIT 5;'); $cache->setContent($players); $cache->save(); } else { $players = $cache->load(); } if ($players) { $count = 1; foreach ($players as $player) { echo "{$count} - <a href='characterprofile.php?name=" . $player['name'] . "'>" . $player['name'] . "</a> (" . $player['level'] . ").<br>"; $count++; } } ?> <br> </div>