cache_starred_images - make scheduled tasks intervals configurable

This commit is contained in:
Andrew Dolgov 2025-05-27 08:27:49 +03:00
parent 0787af48ff
commit 0688e6dadd
No known key found for this signature in database
GPG Key ID: 1A56B4FA25D4AF2A

View File

@ -1,6 +1,9 @@
<?php
class Cache_Starred_Images extends Plugin {
const SCHEDULE_CACHE_STARRED_IMAGES = "SCHEDULE_CACHE_STARRED_IMAGES";
const SCHEDULE_CACHE_STARRED_IMAGES_EXPIRE_CACHES = "SCHEDULE_CACHE_STARRED_IMAGES_EXPIRE_CACHES";
/** @var PluginHost $host */
private $host;
@ -24,6 +27,9 @@ class Cache_Starred_Images extends Plugin {
$this->cache = DiskCache::instance("starred-images");
$this->cache_status = DiskCache::instance("starred-images.status-files");
Config::add(self::SCHEDULE_CACHE_STARRED_IMAGES, "@hourly", Config::T_STRING);
Config::add(self::SCHEDULE_CACHE_STARRED_IMAGES_EXPIRE_CACHES, "@daily", Config::T_STRING);
if (!$this->cache->exists(".no-auto-expiry"))
$this->cache->put(".no-auto-expiry", "");
@ -32,7 +38,9 @@ class Cache_Starred_Images extends Plugin {
if ($this->cache->is_writable() && $this->cache_status->is_writable()) {
$host->add_scheduled_task($this, "cache_starred_images", "@hourly", function() {
$host->add_scheduled_task($this, "cache_starred_images",
Config::get(self::SCHEDULE_CACHE_STARRED_IMAGES), function() {
Debug::log("caching media of starred articles for user " . $this->host->get_owner_uid() . "...");
$sth = $this->pdo->prepare("SELECT content, ttrss_entries.title,
@ -66,7 +74,8 @@ class Cache_Starred_Images extends Plugin {
}
});
$host->add_scheduled_task($this, "expire_caches", "@daily", function() {
$host->add_scheduled_task($this, "expire_caches",
Config::get(self::SCHEDULE_CACHE_STARRED_IMAGES_EXPIRE_CACHES), function() {
Debug::log("expiring {$this->cache->get_dir()} and {$this->cache_status->get_dir()}...");