2023-08-25 08:23:53 -07:00
|
|
|
<?php
|
2023-08-30 05:50:01 -07:00
|
|
|
if (!function_exists("apcu_fetch"))
|
|
|
|
error_log("apcu is not installed! Please consider installing php-pecl-apcu for significant performance improvements");
|
|
|
|
|
|
|
|
|
2023-08-25 08:23:53 -07:00
|
|
|
function load_cooldowns() {
|
2023-08-25 11:09:06 -07:00
|
|
|
if (function_exists("apcu_fetch"))
|
2023-08-25 10:57:23 -07:00
|
|
|
return apcu_exists("cooldowns") ? apcu_fetch("cooldowns") : array();
|
|
|
|
return array();
|
2023-08-25 08:23:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function save_cooldowns($cooldowns) {
|
2023-08-25 11:09:06 -07:00
|
|
|
if (function_exists("apcu_store"))
|
2023-08-25 10:57:23 -07:00
|
|
|
apcu_store("cooldowns", $cooldowns);
|
2023-08-25 08:23:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_cooldown($instance, $timeout, $cooldowns) {
|
|
|
|
$cooldowns[$instance] = time() + $timeout;
|
|
|
|
save_cooldowns($cooldowns);
|
|
|
|
return $cooldowns;
|
|
|
|
}
|
|
|
|
|
|
|
|
function has_cooldown($instance, $cooldowns) {
|
|
|
|
return ($cooldowns[$instance] ?? 0) > time();
|
|
|
|
}
|
2023-08-30 05:50:01 -07:00
|
|
|
|
|
|
|
function has_cached_results($url) {
|
|
|
|
if (function_exists("apcu_exists"))
|
|
|
|
return apcu_exists("cached:$url");
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-08-30 05:58:47 -07:00
|
|
|
function store_cached_results($url, $results, $ttl = 0) {
|
2023-08-30 05:50:01 -07:00
|
|
|
if (function_exists("apcu_store") && !empty($results))
|
2023-08-30 05:58:47 -07:00
|
|
|
return apcu_store("cached:$url", $results, $ttl);
|
2023-08-30 05:50:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function fetch_cached_results($url) {
|
|
|
|
if (function_exists("apcu_fetch"))
|
|
|
|
return apcu_fetch("cached:$url");
|
|
|
|
|
|
|
|
return array();
|
|
|
|
}
|
2023-08-25 08:23:53 -07:00
|
|
|
?>
|