From 814c2b44fcc500d2f8f2acb7c9443079908ddaa2 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Wed, 8 Apr 2015 01:05:46 +0200 Subject: Cache filedata This brings down render time of a multipaste with 180 items from ~180ms to ~80ms. Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'application/helpers/filebin_helper.php') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index b5df4f877..7fd25d5f4 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -282,6 +282,23 @@ function stateful_client() return true; } +function init_cache() +{ + static $done = false; + if ($done) {return;} + + $CI =& get_instance(); + $CI->load->driver('cache', array('adapter' => $CI->config->item("cache_backend"))); + $done = true; +} + +function delete_cache($key) +{ + init_cache(); + $CI =& get_instance(); + $CI->cache->delete($key); +} + /** * Cache the result of the function call in the cache backend. * @param key cache key to use @@ -291,8 +308,8 @@ function stateful_client() */ function cache_function($key, $ttl, $function) { + init_cache(); $CI =& get_instance(); - $CI->load->driver('cache', array('adapter' => $CI->config->item("cache_backend"))); if (! $content = $CI->cache->get($key)) { $content = $function(); $CI->cache->save($key, $content, $ttl); -- cgit v1.2.3-24-g4f1b