summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--application/helpers/filebin_helper.php18
1 files changed, 18 insertions, 0 deletions
diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php
index 71ce7e6ca..e5637ce94 100644
--- a/application/helpers/filebin_helper.php
+++ b/application/helpers/filebin_helper.php
@@ -265,4 +265,22 @@ function stateful_client()
return true;
}
+/**
+ * Cache the result of the function call
+ * @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($key, $ttl, $function)
+{
+ $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);
+ }
+ return $content;
+}
+
# vim: set noet: