From 648e3cb5d45fe2a1318b3115439b5e64afa45ed9 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 2 Apr 2015 17:21:19 +0200 Subject: helper: Add cache_function_full Signed-off-by: Florian Pritz --- application/helpers/filebin_helper.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index 2604cfe4e..b5df4f877 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -283,7 +283,7 @@ function stateful_client() } /** - * Cache the result of the function call + * Cache the result of the function call in the cache backend. * @param key cache key to use * @param ttl time to live for the cache entry * @param function function to call @@ -300,6 +300,23 @@ function cache_function($key, $ttl, $function) return $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; +} + // Return mimetype of file function mimetype($file) { $fileinfo = new finfo(FILEINFO_MIME_TYPE); -- cgit v1.2.3-24-g4f1b