mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 00:06:55 +02:00
Add support for a WireCacheInterface::maintenance($obj) method as mentioned by @BitPoet
This commit is contained in:
@@ -796,4 +796,27 @@ interface WireCacheInterface {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function expireAll();
|
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);
|
||||||
}
|
}
|
||||||
|
@@ -799,13 +799,19 @@ class WireCache extends Wire {
|
|||||||
$forceRun = false;
|
$forceRun = false;
|
||||||
$database = $this->wire()->database;
|
$database = $this->wire()->database;
|
||||||
$config = $this->wire()->config;
|
$config = $this->wire()->config;
|
||||||
|
$cacher = $this->cacher();
|
||||||
|
$useCacherMaint = method_exists($cacher, 'maintenance');
|
||||||
|
|
||||||
if(!$database || !$config) return false;
|
if(!$database || !$config) return false;
|
||||||
|
|
||||||
if(is_object($obj)) {
|
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
|
// check to see if it is worthwhile to perform this kind of maintenance at all
|
||||||
if($this->usePageTemplateMaintenance === null) {
|
if($this->usePageTemplateMaintenance === null) {
|
||||||
$rows = $this->cacher()->find(array(
|
$rows = $cacher->find(array(
|
||||||
'get' => array('name'),
|
'get' => array('name'),
|
||||||
'expiresMode' => 'OR',
|
'expiresMode' => 'OR',
|
||||||
'expires' => array(
|
'expires' => array(
|
||||||
@@ -863,7 +869,14 @@ class WireCache extends Wire {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// perform general maintenance now
|
// 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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user