LibreY- privacy respecting meta search engine |
git clone git://git.acid.vegas/LibreY.git |
Log | Files | Refs | Archive | README | LICENSE |
cooldowns.php (1321B)
1 <?php 2 if (!function_exists("apcu_fetch")) 3 error_log("apcu is not installed! Please consider installing php-pecl-apcu for significant performance improvements"); 4 5 6 function load_cooldowns() { 7 if (function_exists("apcu_fetch")) 8 return apcu_exists("cooldowns") ? apcu_fetch("cooldowns") : array(); 9 return array(); 10 } 11 12 function save_cooldowns($cooldowns) { 13 if (function_exists("apcu_store")) 14 apcu_store("cooldowns", $cooldowns); 15 } 16 17 function set_cooldown($instance, $timeout, $cooldowns) { 18 $cooldowns[$instance] = time() + $timeout; 19 save_cooldowns($cooldowns); 20 return $cooldowns; 21 } 22 23 function has_cooldown($instance, $cooldowns) { 24 return ($cooldowns[$instance] ?? 0) > time(); 25 } 26 27 function has_cached_results($url) { 28 if (function_exists("apcu_exists")) 29 return apcu_exists("cached:$url"); 30 31 return false; 32 } 33 34 function store_cached_results($url, $results, $ttl = 0) { 35 if (function_exists("apcu_store") && !empty($results)) 36 return apcu_store("cached:$url", $results, $ttl); 37 } 38 39 function fetch_cached_results($url) { 40 if (function_exists("apcu_fetch")) 41 return apcu_fetch("cached:$url"); 42 43 return array(); 44 } 45 ?>