diff --git a/core/Cache/PersistentCache.php b/core/Cache/PersistentCache.php index cd695bde2d5011b79b31a36a17dbefa300faf4bf..2596b950a590f8a3b24b76a854f0e84da849db2a 100644 --- a/core/Cache/PersistentCache.php +++ b/core/Cache/PersistentCache.php @@ -96,7 +96,7 @@ class PersistentCache public static function _reset() { - self::$content = null; + self::$content = array(); } /** @@ -106,6 +106,9 @@ class PersistentCache { if (is_null(self::$storage)) { self::$storage = new CacheFile('tracker', 43200); + self::$storage->addOnDeleteCallback(function () { + PersistentCache::_reset(); + }); } return self::$storage; diff --git a/core/CacheFile.php b/core/CacheFile.php index 94ad253020ad40b83244a227cf99e10c9cabbafb..7a1c824ff8977eb8a4de2be58b1c06a0b7a22d07 100644 --- a/core/CacheFile.php +++ b/core/CacheFile.php @@ -36,6 +36,11 @@ class CacheFile */ const MINIMUM_TTL = 60; + /** + * @var \Callable[] + */ + private static $onDeleteCallback = array(); + /** * @param string $directory directory to use * @param int $timeToLiveInSeconds TTL @@ -182,6 +187,11 @@ class CacheFile return false; } + public function addOnDeleteCallback($onDeleteCallback) + { + self::$onDeleteCallback[] = $onDeleteCallback; + } + /** * A function to delete all cache entries in the directory */ @@ -193,6 +203,12 @@ class CacheFile }; Filesystem::unlinkRecursive($this->cachePath, $deleteRootToo = false, $beforeUnlink); + + if (!empty(self::$onDeleteCallback)) { + foreach (self::$onDeleteCallback as $callback) { + $callback(); + } + } } public function opCacheInvalidate($filepath) diff --git a/tests/PHPUnit/Fixture.php b/tests/PHPUnit/Fixture.php index cb5fac1035a97ccd2940fd0e5ff79c3568137d9b..22b09767a3c78c87a916782cd0d4cac1cb3a1a6c 100644 --- a/tests/PHPUnit/Fixture.php +++ b/tests/PHPUnit/Fixture.php @@ -179,7 +179,6 @@ class Fixture extends PHPUnit_Framework_Assert Piwik::setUserHasSuperUserAccess(); Cache::deleteTrackerCache(); - \Piwik\Cache\PersistentCache::_reset(); static::loadAllPlugins($this->getTestEnvironment(), $this->testCaseClass);