summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2013-11-09 22:00:47 +0100
committerFlorian Pritz <bluewind@xinu.at>2013-11-09 22:00:47 +0100
commit853303f104c576ddaaa2e645b7f4334bd2157053 (patch)
treee964941154db00ecb8052a70cfe5987d6ee06dd3
parent4b149b042e97e623e6902b770bbb827cff1986c1 (diff)
implement cache_function to easily cache return values of functions
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-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: