+ /**
+ * @brief Remove outdated data from the cache
+ *
+ * @param integer $maxlevel The maximum cache level that is to be cleared
+ */
+ public static function clear($max_level = CACHE_MONTH) {
+
+ // Clear long lasting cache entries only once a day
+ if (get_config("system", "cache_cleared_day") < time() - self::duration(CACHE_DAY)) {
+ if ($max_level == CACHE_MONTH) {
+ q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+ dbesc(datetime_convert('UTC','UTC',"now - 30 days")), intval(CACHE_MONTH));
+ }
+
+ if ($max_level <= CACHE_WEEK) {
+ q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+ dbesc(datetime_convert('UTC','UTC',"now - 7 days")), intval(CACHE_WEEK));
+ }
+
+ if ($max_level <= CACHE_DAY) {
+ q("DELETE FROM `cache` WHERE `updated` < '%s' AND `expire_mode` = %d",
+ dbesc(datetime_convert('UTC','UTC',"now - 1 days")), intval(CACHE_DAY));
+ }
+ set_config("system", "cache_cleared_day", time());
+ }