diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-04-02 17:21:19 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-04-02 17:21:19 +0200 |
commit | 648e3cb5d45fe2a1318b3115439b5e64afa45ed9 (patch) | |
tree | 12c1a50b9eb84e52b476bdabf333e0cb62685802 /application/helpers | |
parent | 601bd43a24f88f8f0e129743e7bc0b0d64eac887 (diff) |
helper: Add cache_function_full
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/helpers')
-rw-r--r-- | application/helpers/filebin_helper.php | 19 |
1 files changed, 18 insertions, 1 deletions
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); |