1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-30 19:00:10 +02:00

[1.7.0] Add versioning to serializer cache

- Make some AttrDef member-variables lazy-loading to save serialization space, clean up others
- Refactor get*Definition() methods

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1116 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-05-29 18:19:42 +00:00
parent 426fbd1f97
commit d1187ed331
11 changed files with 169 additions and 71 deletions

View File

@@ -33,7 +33,23 @@ class HTMLPurifier_DefinitionCache
* @param Instance of HTMLPurifier_Config
*/
function generateKey($config) {
return md5(serialize($config->getBatch($this->type)));
$version = $config->version;
$revision = $config->revision;
return $version . '-' . $revision . '-' . md5(serialize($config->getBatch($this->type)));
}
/**
* Tests whether or not a key is old with respect to the configuration's
* version and revision number.
* @param $key Key to test
* @param $config Instance of HTMLPurifier_Config to test against
*/
function isOld($key, $config) {
list($version, $revision, $hash) = explode('-', $key, 3);
$compare = version_compare($version, $config->version);
if ($compare > 0) return false;
if ($compare == 0 && $revision >= $config->revision) return false;
return true;
}
/**
@@ -99,10 +115,16 @@ class HTMLPurifier_DefinitionCache
/**
* Clears all objects from cache
*/
function flush($config) {
function flush() {
trigger_error('Cannot call abstract method', E_USER_ERROR);
}
/**
* Clears all expired (older version or revision) objects from cache
*/
function cleanup($config) {
trigger_error('Cannot call abstract method', E_USER_ERROR);
}
}
?>