function get_image_from_cache($checksum) { $cache_file = get_cache_filename($checksum); if (!is_cached($checksum)) { error('Problem with cache image.'); } $cache_entry = json_decode(file_get_contents($cache_file)); if (empty($cache_entry->mime_type) || empty($cache_entry->image_data)) { error('Problem with cache image.'); } $image_data = base64_decode($cache_entry->image_data); header('Content-Type: ' . $cache_entry->mime_type); echo $image_data; }
} $newitem = $output->createNewItem(); $newitem->setTitle($feed_item_title); if (isset($permalink) && is_string($permalink)) { $newitem->setLink($permalink); } else { $permalink = $item->get_permalink(); $newitem->setLink($permalink); } if (isset($permalink) && is_string($permalink) && strlen($permalink) < 9) { continue; } //if ($permalink && ($response = $http->get($permalink, true)) && $response['status_code'] < 300) { // Allowing error codes - some sites return correct content with error status // e.g. prospectmagazine.co.uk returns 403 $cached_page = is_cached($permalink); if ($cached_page) { debug('Loading processed page form cache...'); $html = get_cached($permalink); $extraction_successful = true; } else { if (($response = $http->get($permalink, true)) && ($response['status_code'] < 300 || $response['status_code'] > 400)) { $effective_url = $response['effective_url']; if (!url_allowed($effective_url)) { continue; } // check if action defined for returned Content-Type $mime_info = get_mime_action_info($response['headers']); if (isset($mime_info['action'])) { if ($mime_info['action'] == 'exclude') { continue;
case 'errata': $smarty->assign('errata', get_dict_errata(isset($_GET['all']), isset($_GET['rand']))); $smarty->display('dict/errata.tpl'); break; case 'pending': $skip = isset($_GET['skip']) ? $_GET['skip'] : 0; $smarty->assign('data', get_pending_updates($skip)); $smarty->display('dict/pending.tpl'); break; case 'reannot': update_pending_tokens($_POST['rev_id'], isset($_POST['smart_mode']) && $_POST['smart_mode'] == 'on'); header("Location:dict.php?act=pending"); break; case 'absent': $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); $smarty->setCacheLifetime(3600); if (!is_cached('dict/absent.tpl')) { $smarty->assign('words', get_top_absent_words()); } $smarty->display('dict/absent.tpl'); break; default: $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); $smarty->setCacheLifetime(600); if (!is_cached('dict/main.tpl', (int) user_has_permission(PERM_DICT))) { $smarty->assign('stats', get_dict_stats()); $smarty->assign('dl', get_downloads_info()); } $smarty->display('dict/main.tpl', (int) user_has_permission(PERM_DICT)); } log_timing();
/** * show a page */ function controller_show($args) { // most of these checks are only necessary if the client calls // page/show directly page_canonical($args[0][0]); $page = $args[0][0]; if (!page_exists($page)) { log_msg('info', 'controller_show: page ' . quot($page) . ' not found, serving 404'); hotglue_error(404); } // serve from page if possible if (0 < CACHE_TIME && is_cached('page', $page, CACHE_TIME)) { serve_cached('page', $page); die; } // otherwise create page on the fly load_modules('glue'); default_html(false); $cache_page = true; render_page(array('page' => $page, 'edit' => false)); // the $cache_page parameter is set by the html_finalize() $html = html_finalize($cache_page); echo $html; // and cache it if (0 < CACHE_TIME && $cache_page) { cache_output('page', $page, $html); } }
$smarty->display('stats.tpl', $cache_key); break; case 'tag_stats': $smarty->assign('active_page', 'stats'); $smarty->assign('stats', get_tag_stats()); $smarty->display('tag_stats.tpl'); break; case 'genre_stats': $smarty->assign('active_page', 'stats'); $smarty->assign('stats', get_common_stats()); $smarty->display('genre_stats.tpl'); break; case 'charts': $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); $smarty->setCacheLifetime(300); if (!is_cached('charts.tpl')) { $smarty->assign('words_chart', get_word_stats_for_chart()); $smarty->assign('ambig_chart', get_ambiguity_stats_for_chart()); $smarty->assign('pools_stats', get_pools_stats()); $smarty->assign('annot_chart', get_annot_stats_for_chart()); } $smarty->display('charts.tpl'); break; case 'pool_charts': $smarty->assign('main', get_extended_pools_stats()); $smarty->assign('moder', get_moderation_stats()); $smarty->display('ext_charts.tpl'); break; case 'export': $smarty->assign('active_page', 'downloads'); $smarty->display('static/doc/export.tpl');
function are_feeds_cached() { global $feeds_ch, $feeds_d_ch; if (is_cached($feeds_ch) == true && is_cached($feeds_d_ch) == true) { return true; } else { return false; } }
if (isset($_GET['set_id'])) { $set_id = (int) $_GET['set_id']; } else { $set_id = 0; } if (isset($_GET['skip'])) { $skip = (int) $_GET['skip']; } else { $skip = 0; } if (isset($_GET['maa'])) { $maa = $_GET['maa'] ? 1 : 0; } else { $maa = 0; } if (isset($_GET['user_id'])) { $user_id = (int) $_GET['user_id']; } else { $user_id = 0; } $smarty->setCaching(Smarty::CACHING_LIFETIME_SAVED); $smarty->setCacheLifetime(90); $cache_id = "{$sent_id}@{$set_id}@{$skip}@{$maa}@{$user_id}"; if (!is_cached('history.tpl', $cache_id)) { $smarty->assign('history', main_history($sent_id, $set_id, $skip, $maa, $user_id)); $smarty->assign('skip', $skip); $smarty->assign('maa', $maa); $smarty->assign('user_id', $user_id); } $smarty->display('history.tpl', $cache_id); log_timing();
function treat_file_by_extension($file_path, array $params = array()) { $exts_cfg = settings('extensions_callbacks'); $file_ext = substr($file_path, -(strlen($file_path) - strrpos($file_path, '.') - 1)); $content = null; $template = false; if (array_key_exists($file_ext, $exts_cfg)) { if (substr_count($file_path, '.') > 1) { $alt_fp = substr($file_path, 0, strlen($file_path) - strlen($file_ext) - 1); $tmp_file = get_cache_path(basename($alt_fp)); if (is_cached($tmp_file, filemtime($file_path))) { return treat_file_by_extension($tmp_file, $params); } } $_cb = $exts_cfg[$file_ext]; if (function_exists($_cb)) { list($content, $template) = callback($_cb, $file_path, $params); } else { throw new ErrorException(sprintf('Callback "%s" defined for extension type "%s" not found!', $_cb, $file_ext)); } if (substr_count($file_path, '.') > 1) { set_cache($tmp_file, $content); return treat_file_by_extension($tmp_file, $params); } } else { throw new ErrorException(sprintf('Unknown page extension "%s"!', $file_ext)); } return array($content, $template); }
// Just a test... // http://www.xeweb.net/2010/01/15/simple-php-caching/ $cache_expires = 120; $cache_folder = "/dev/shm/"; function is_cached($file) { global $cache_folder, $cache_expires; $cachefile = $cache_folder . $file; $cachefile_created = file_exists($cachefile) ? @filemtime($cachefile) : 0; return time() - $cache_expires < $cachefile_created; } function read_cache($file) { global $cache_folder; $cachefile = $cache_folder . $file; return file_get_contents($cachefile); } function write_cache($file, $out) { global $cache_folder; $cachefile = $cache_folder . $file; $fp = fopen($cachefile, 'w'); fwrite($fp, $out); fclose($fp); } $cache_file = md5($_SERVER['REQUEST_URI']) . '.cache'; if (is_cached($cache_file)) { echo read_cache($cache_file); exit; } ob_start();
<?php require "Smarty.class.php"; require "boxer.class.php"; $smarty = new Smarty(); $smarty->caching = 1; try { // If template not already cached, retrieve the appropriate information. if (!is_cached("boxerbio.tpl", $_GET['boxerid'])) { $bx = new boxer(); if (!$bx->retrieveBoxer($_GET['boxerid'])) { throw new Exception("Boxer not found."); } // Create the appropriate Smarty variables $smarty->assign("name", $bx->getName()); $smarty->assign("bio", $bx->getBio()); } /* Render the template, caching it and assigning it the name * represented by $_GET['boxerid']. If already cached, then * retrieve that cached template */ $smarty->display("boxerbio.tpl", $_GET['boxerid']); } catch (Exception $e) { echo $e->getMessage(); } ?>