function get_filedata($id) { return cache_function("filedatav2-{$id}", 300, function () use($id) { $query = $this->db->select('files.id, hash, file_storage.id storage_id, filename, mimetype, files.date, user, filesize')->from('files')->join('file_storage', 'file_storage.id = files.file_storage_id')->where('files.id', $id)->limit(1)->get(); if ($query->num_rows() > 0) { $data = $query->row_array(); $data["data_id"] = $data["hash"] . "-" . $data["storage_id"]; return $data; } else { return false; } }); }
public static function get_lexers() { return cache_function('lexers-v2', 1800, function () { $last_desc = ""; foreach (self::get_pygments_info() as $lexer) { $desc = $lexer['fullname']; $name = $lexer['names'][0]; if ($desc == $last_desc) { continue; } $last_desc = $desc; $lexers[$name] = $desc; } $lexers["text"] = "Plain text"; return $lexers; }); }
function thumbnail() { $id = $this->uri->segment(3); if (!$this->mfile->valid_id($id)) { return $this->_non_existent(); } $etag = "{$id}-thumb"; handle_etag($etag); $thumb_size = 150; $cache_timeout = 60 * 60 * 24 * 30; # 1 month $filedata = $this->mfile->get_filedata($id); if (!$filedata) { throw new \exceptions\ApiException("file/thumbnail/filedata-unavailable", "Failed to get file data"); } $cache_key = $filedata['data_id'] . '_thumb_' . $thumb_size; $thumb = cache_function($cache_key, $cache_timeout, function () use($filedata, $thumb_size) { $CI =& get_instance(); $img = new libraries\Image($this->mfile->file($filedata["data_id"])); $img->makeThumb($thumb_size, $thumb_size); $thumb = $img->get(IMAGETYPE_JPEG); return $thumb; }); $this->output->set_header("Cache-Control:max-age=31536000, public"); $this->output->set_header("Expires: " . date("r", time() + 365 * 24 * 60 * 60)); $this->output->set_content_type("image/jpeg"); $this->output->set_output($thumb); }
</div> </div> <?php } ?> <!-- content --> <div id="content"> <div class="row-1"> <div class="inside"> <div class="container"> <div class="menu2"> <div> <?php if (isAuthenticated()) { showMenu(); } ?> </div> </div> <?php if (isAuthenticated()) { if (isset($_GET['callee'])) { cache_function("showBreadCrumb", array("pageid" => $_SESSION['pageid'], "callee" => $_GET['callee'])); } else { cache_function("showBreadCrumb", array("pageid" => $_SESSION['pageid'])); } echo "<hr>\n"; } ?> <div class="content">
/** * Cache the result of a function call in the cache backend and in the memory of this process. * @param key cache key to use * @param ttl time to live for the cache entry * @param function function to call * @return return value of function (will be cached) */ function cache_function_full($key, $ttl, $function) { $local_key = 'cache_function-' . $key; if (static_storage($local_key) !== null) { return static_storage($local_key); } $ret = cache_function($key, $ttl, $function); static_storage($local_key, $ret); return $ret; }