From 1ebace1417563a74967e0c45fb3998a26770eb47 Mon Sep 17 00:00:00 2001 From: rdalverny Date: Sat, 22 Jan 2022 21:41:44 +0100 Subject: Prune cached HTML when changing feeds list --- app/classes/Cache.php | 15 +++++++++++++++ public/admin/subscriptions.php | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/app/classes/Cache.php b/app/classes/Cache.php index 474c560..6a5b7e7 100644 --- a/app/classes/Cache.php +++ b/app/classes/Cache.php @@ -115,6 +115,21 @@ class Cache return false; } + + public static function prune(string $group, ?string $id = null) : void + { + if (is_null($id)) { + $filenames = glob(self::$store . self::$prefix . "{$group}_*"); + } else { + $filenames = [self::getFilename($group, $id)]; + } + + foreach ($filenames as $filename) { + if (is_file($filename)) { + unlink($filename); + } + } + } /** * Builds a filename/path from group, id and diff --git a/public/admin/subscriptions.php b/public/admin/subscriptions.php index 418e354..236ac46 100755 --- a/public/admin/subscriptions.php +++ b/public/admin/subscriptions.php @@ -22,6 +22,9 @@ if (isset($_POST['upload']) && $newOpml = new Opml(); $newOpml->parse(file_get_contents($_FILES['opml']['tmp_name'])); OpmlManager::save($newOpml, $opmlFile); + + Cache::setStore($PlanetConfig->getCacheDir() . '/'); + Cache::prune("html"); } elseif (isset($_POST['opml']) || isset($_POST['add'])) { // Load old OPML $oldOpml = OpmlManager::load($opmlFile); @@ -79,6 +82,9 @@ if (isset($_POST['upload']) && // Save new OPML OpmlManager::save($newOpml, $opmlFile); + + Cache::setStore($PlanetConfig->getCacheDir() . '/'); + Cache::prune("html"); } header("Location: index.php"); die(); -- cgit v1.2.1