Delete the cache entry when the post is changed or deleted

This commit is contained in:
Michael 2022-09-06 21:51:47 +00:00
parent 7c9f10e58f
commit da658cbf1d
6 changed files with 38 additions and 9 deletions

View file

@ -36,17 +36,18 @@ class PageCache
* Add content to the page cache
*
* @param string $page
* @param int $uriid
* @param mixed $content
* @return void
*/
public static function add(string $page, $content)
public static function add(string $page, int $uriid, $content)
{
if (!DI::config()->get('system', 'pagecache')) {
return;
}
DBA::delete('pagecache', ["`fetched` < ?", DateTimeFormat::utc('now - 5 minutes')]);
DBA::insert('pagecache', ['page' => $page, 'content' => serialize($content), 'fetched' => DateTimeFormat::utcNow()], Database::INSERT_UPDATE);
DBA::insert('pagecache', ['page' => $page, 'uri-id' => $uriid, 'content' => serialize($content), 'fetched' => DateTimeFormat::utcNow()], Database::INSERT_UPDATE);
Logger::debug('Page added', ['page' => $page]);
}
@ -70,4 +71,15 @@ class PageCache
return unserialize($pagecache['content']);
}
/**
* Delete the pagecache via its connected uri-id
*
* @param integer $uriid
* @return void
*/
public static function deleteByUriId(int $uriid)
{
DBA::delete('pagecache', ['uri-id' => $uriid]);
}
}