function checkCache() { $app = JFactory::getApplication(); $user = JFactory::getUser(); if ($this->_recache) { $this->_cache->remove($this->_cache_key); return; } if ($app->isAdmin() || $this->isDisabled() || count($app->getMessageQueue()) || $user->get('admin') || $app->input->getMethod() !== 'GET') { return; } $data = $this->_cache->get($this->_cache_key); if (false === strpos($data, sprintf('cached:%d', $this->_cache_version))) { // Logger::d('ERROR: Cache version mismatch'); return; } if ($data !== false) { // Set cached body. $app->setBody($data); echo $app->toString($app->get('gzip')); // Logger::d(__METHOD__.' from cache'); $app->close(); exit; } }
/** * @param $checksum * * @return bool|mixed */ protected function isOutputExpired(RokBooster_Compressor_IGroup $group, $is_wrapped = true) { $oc = RokBooster_Compressor_OutputContainerFactory::create($group, $this->options); if (!$oc->doesExist($is_wrapped)) { return true; } if ($expired = $oc->isExpired($is_wrapped)) { $files_changed = false; if ($file_group = $this->file_info_cache->get($group->getChecksum() . '_fileinfo')) { $file_group = unserialize($file_group); /** @var $file RokBooster_Compressor_File */ foreach ($file_group as $file) { if (file_exists($file->getPath()) && is_readable($file->getPath())) { if ($file->hasChanged()) { $files_changed = true; break; } } else { $this->file_info_cache->remove($group->getChecksum() . '_fileinfo'); $files_changed = true; break; } } } else { $files_changed = true; } if (!$files_changed) { $oc->setAsValid(); return false; } } return $expired; }
/** * @param $checksum * * @return bool|mixed */ protected function isCacheExpired($checksum) { if (!$this->cache->doesCacheExist($checksum)) { return true; } if ($expired = $this->cache->isCacheExpired($checksum)) { $files_changed = false; if ($file_group = $this->file_info_cache->get($checksum . '_fileinfo')) { $file_group = unserialize($file_group); /** @var $file RokBooster_Compressor_File */ foreach ($file_group as $file) { if (file_exists($file->getPath()) && is_readable($file->getPath())) { if ($file->hasChanged()) { $files_changed = true; break; } } else { $this->file_info_cache->remove($checksum . '_fileinfo'); $files_changed = true; break; } } } else { $files_changed = true; } if (!$files_changed) { $this->cache->setCacheAsValid($checksum); return false; } } return $expired; }
function save($content, $id) { // Store the cache string for ($i = 0; $i < 5; $i++) { if (parent::store(serialize($content), $id)) { return; } } parent::remove($id); }
/** * Testing remove(). * * @return void */ public function testRemove() { $options = array('storage' => 'file'); $this->object = JCache::getInstance('output', $options); $this->object->setCaching(true); $this->object->store('Now is the time for all good people to throw a party.', 42, ''); $this->object->store('And this is the cache that tries men\'s souls', 43, ''); $this->assertThat($this->object->get(43, ''), $this->equalTo('And this is the cache that tries men\'s souls'), 'Should retrieve the data properly'); $this->assertThat($this->object->remove(43, ''), $this->isTrue(), 'Should remove cached data'); $this->assertThat($this->object->get(43, ''), $this->isFalse(), 'Should not retrieve the data properly'); $this->assertThat($this->object->get(42, ''), $this->equalTo('Now is the time for all good people to throw a party.'), 'Should retrieve the data properly'); }
/** * Testing remove(). * * @return void */ public function testRemove() { $options = array('storage' => 'file'); $this->object = JCache::getInstance('output', $options); $this->object->setCaching(true); $this->object->store($this->testData_A, 42, ''); $this->object->store($this->testData_B, 43, ''); $this->assertEquals($this->testData_B, $this->object->get(43, '')); $this->assertTrue($this->object->remove(43, '')); $this->assertFalse($this->object->get(43, '')); $this->assertEquals($this->testData_A, $this->object->get(42, '')); }
static function fetchXML($params, $force = 0) { $rssurl = $params->get('rss_url', ''); $items_limit = intval($params->get('items_limit', 10)); $doCache = intval($params->get('scr_cache', 1)); $CacheTime = intval($params->get('cache_time', 3600)); $twitter_timeline = $params->get('twitter_timeline', 'user'); $username = $params->get('twitter_username', ''); $password = $params->get('twitter_password', ''); $list = $params->get('twitter_list', ''); if ($twitter_timeline == 'friends') { $rssurl = 'http://api.twitter.com/1/statuses/friends_timeline.xml'; } else { if ($twitter_timeline == 'mentions') { $rssurl = 'http://api.twitter.com/1/statuses/mentions.xml'; } else { if ($twitter_timeline == 'list') { $rssurl = 'http://api.twitter.com/1/' . urlencode($username) . '/lists/' . urlencode($list) . '/statuses.xml'; } else { if ($twitter_timeline == 'user_rt' && $username != '') { $rssurl = 'http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=' . urlencode($username) . '&include_rts=true'; } else { if ($username != '') { $rssurl = 'http://api.twitter.com/1/statuses/user_timeline/' . urlencode($username) . '.xml'; } else { $rssurl = str_replace('.rss', '.xml', $rssurl); } } } } } $feed_desc = 1; $item_desc = 1; $feed_array = array(); $xmlDoc =& JFactory::getXMLParser('Simple'); if ($doCache) { if (!class_exists('JCache')) { require_once JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'cache' . DS . 'cache.php'; } $options = array('defaultgroup' => 'mod_ajaxscroller', 'lifetime' => $CacheTime, 'checkTime' => true, 'caching' => true); $cache = new JCache($options); $cache->setLifeTime($CacheTime); if ($force) { // delete the cache, force the new fetch $cache->remove(md5($rssurl), 'mod_ajaxscroller'); } if ($string = $cache->get(md5($rssurl), 'mod_ajaxscroller')) { $xmlDoc->loadString($string); } else { $xml = simplexml_load_file($rssurl); $string = $xml->asXML(); $string = str_replace('georss:', 'georss_', $string); // simplexml doesn't like ':' $xmlDoc->loadString($string); $cache->store($xmlDoc->document->toString(), md5($rssurl)); } } else { $xml = simplexml_load_file($rssurl); $string = $xml->asXML(); $string = str_replace('georss:', 'georss_', $string); // simplexml doesn't like ':' $xmlDoc->loadString($string); } $root =& $xmlDoc->document; $statuses =& $root->children(); $length = count($statuses); $total = $items_limit && $items_limit < $length ? $items_limit : $length; if ($total == 0) { $feed_array = $xmlDoc->loadString($string); } for ($i = 0; $i < $total; $i++) { $status =& $statuses[$i]; $id =& $status->getElementByPath('id')->data(); $created_at =& $status->getElementByPath('created_at')->data(); $text =& $status->getElementByPath('text')->data(); $source =& $status->getElementByPath('source')->data(); $in_reply_to_status_id =& $status->getElementByPath('in_reply_to_status_id')->data(); $in_reply_to_user_id =& $status->getElementByPath('in_reply_to_user_id')->data(); $in_reply_to_screen_name =& $status->getElementByPath('in_reply_to_screen_name')->data(); $user_id =& $status->getElementByPath('user')->getElementByPath('id')->data(); $user_screen_name =& $status->getElementByPath('user')->getElementByPath('screen_name')->data(); $user_profile_image_url =& $status->getElementByPath('user')->getElementByPath('profile_image_url')->data(); $feed_array[$i]['item_href'] = 'http://twitter.com/' . $user_screen_name . '/statuses/' . $id; $feed_array[$i]['item_date'] = $created_at; $feed_array[$i]['item_title'] = $user_screen_name; //$text = htmlentities($text); $feed_array[$i]['item_desc'] = modAjaxScrollerCommonHelper::ajax_scroller_format_twitter($text, $params, $user_profile_image_url, $user_screen_name, $created_at, $source, $in_reply_to_user_id, $in_reply_to_screen_name, $in_reply_to_status_id); } return $feed_array; }
/** * Clears cache of specified identifier of group * * @param string $groupName Name of group * @param string $identifier Identifier * * @return boolean */ public function clearCache($groupName, $identifier) { return $this->cache->remove($identifier, $groupName); }