diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-11-09 22:18:51 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-11-09 22:31:46 +0100 |
commit | 4a92fbad4beb9d27f4bbfa4f9360bddf455e671f (patch) | |
tree | b7487a1c46331187fc1d04ed7e3681d7c17977ab | |
parent | 389d2aeb62ff8755691392953ae2044b7fad5ada (diff) |
use cache_function() everywhere
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/file.php | 28 | ||||
-rw-r--r-- | application/models/mfile.php | 9 |
2 files changed, 16 insertions, 21 deletions
diff --git a/application/controllers/file.php b/application/controllers/file.php index b0561a52c..14736431b 100644 --- a/application/controllers/file.php +++ b/application/controllers/file.php @@ -138,33 +138,31 @@ class File extends MY_Controller { $this->data['lexers'] = $this->mfile->get_lexers(); $this->data['filedata'] = $filedata; - // highlight the file and chache the result - $this->load->driver('cache', array('adapter' => $this->config->item("cache_backend"))); - if (! $cached = $this->cache->get($filedata['hash'].'_'.$lexer)) { - $cached = array(); + // highlight the file and cache the result + $highlit = cache_function($filedata['hash'].'_'.$lexer, 100, function() use ($file, $lexer){ + $ret = array(); if ($lexer == "rmd") { ob_start(); echo '<div class="code content table markdownrender">'."\n"; echo '<div class="table-row">'."\n"; echo '<div class="table-cell">'."\n"; - passthru('perl '.FCPATH.'scripts/Markdown.pl '.escapeshellarg($file), $cached["return_value"]); + passthru('perl '.FCPATH.'scripts/Markdown.pl '.escapeshellarg($file), $ret["return_value"]); echo '</div></div></div>'; - $cached["output"] = ob_get_contents(); - ob_end_clean(); + $ret["output"] = ob_get_clean(); } else { - $cached = $this->_colorify($file, $lexer); + $ret = $this->_colorify($file, $lexer); } - if ($cached["return_value"] != 0) { - $ret = $this->_colorify($file, "text"); - $cached["output"] = $ret["output"]; + if ($ret["return_value"] != 0) { + $tmp = $this->_colorify($file, "text"); + $ret["output"] = $tmp["output"]; } - $this->cache->save($filedata['hash'].'_'.$lexer, $cached, 100); - } + return $ret; + }); - if ($cached["return_value"] != 0) { + if ($highlit["return_value"] != 0) { $this->data["error_message"] = "<p>Error trying to process the file. Either the lexer is unknown or something is broken. Falling back to plain text.</p>"; @@ -174,7 +172,7 @@ class File extends MY_Controller { // much magic ({elapsed_time} and {memory_usage}). // Direct echo puts us on the safe side. echo $this->load->view($this->var->view_dir.'/html_header', $this->data, true); - echo $cached["output"]; + echo $highlit["output"]; echo $this->load->view($this->var->view_dir.'/html_footer', $this->data, true); } diff --git a/application/models/mfile.php b/application/models/mfile.php index e70b5c812..d7e301b1e 100644 --- a/application/models/mfile.php +++ b/application/models/mfile.php @@ -339,8 +339,7 @@ class Mfile extends CI_Model { } public function get_lexers() { - $this->load->driver('cache', array('adapter' => $this->config->item("cache_backend"))); - if (! $lexers = $this->cache->get('lexers')) { + return cache_function('lexers', 1800, function() { $lexers = array(); $last_desc = ""; exec("python ".escapeshellarg(FCPATH."scripts/get_lexer_list.py"), $output); @@ -354,10 +353,8 @@ class Mfile extends CI_Model { $lexers[$name] = $desc; } $lexers["text"] = "Plain text"; - $this->cache->save('lexers', $lexers, 1800); - } - - return $lexers; + return $lexers; + }); } public function should_highlight($type) |