1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-07 23:38:29 +02:00

Add support for a WireCacheInterface::maintenance($obj) method as mentioned by @BitPoet

This commit is contained in:
Ryan Cramer
2023-05-30 15:28:03 -04:00
parent f3a0b265ee
commit 02e3e0cd1b
2 changed files with 38 additions and 2 deletions

View File

@@ -796,4 +796,27 @@ interface WireCacheInterface {
*
*/
public function expireAll();
/**
* Optional method to perform maintenance
*
* When present, this method should return true if it handled maintenance or false if it did not.
* If it returns false, WireCache will attempt to perform maintenance instead by calling find and
* delete methods where appropriate.
*
* WireCache passes either null, a Page object or a Template object as the single argument.
* When null is passed, it means "general maintenance". When a Page or Template object is
* passed then it means that the given Page or Template was just saved, and to perform any
* necessary maintenance for that case. If the method handles general maintenance but not
* object maintenance, then it should return true when it receives null, and false when it
* receives a Page or Template.
*
* @param Page|Template|null $obj
* @return bool
* @since 3.0.219
*
* The method below is commented out because it optional and only used only if present:
*
*/
// public function maintenance($obj = null);
}

View File

@@ -799,13 +799,19 @@ class WireCache extends Wire {
$forceRun = false;
$database = $this->wire()->database;
$config = $this->wire()->config;
$cacher = $this->cacher();
$useCacherMaint = method_exists($cacher, 'maintenance');
if(!$database || !$config) return false;
if(is_object($obj)) {
if($useCacherMaint) {
$result = call_user_func_array(array($cacher, 'maintenance'), array($obj));
if($result) return true;
}
// check to see if it is worthwhile to perform this kind of maintenance at all
if($this->usePageTemplateMaintenance === null) {
$rows = $this->cacher()->find(array(
$rows = $cacher->find(array(
'get' => array('name'),
'expiresMode' => 'OR',
'expires' => array(
@@ -863,7 +869,14 @@ class WireCache extends Wire {
}
// perform general maintenance now
return $this->maintenanceGeneral();
if($useCacherMaint) {
$result = (bool) call_user_func_array(array($cacher, 'maintenance'), array(null));
} else {
$result = $this->maintenanceGeneral();
}
return $result;
}
/**