ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_DefinitionCache Class Reference

Abstract class representing Definition cache managers that implements useful common methods and is a factory. More...

+ Inheritance diagram for HTMLPurifier_DefinitionCache:
+ Collaboration diagram for HTMLPurifier_DefinitionCache:

Public Member Functions

 __construct ($type)
 generateKey ($config)
 Generates a unique identifier for a particular configuration.
 isOld ($key, $config)
 Tests whether or not a key is old with respect to the configuration's version and revision number.
 checkDefType ($def)
 Checks if a definition's type jives with the cache's type.
 add ($def, $config)
 Adds a definition object to the cache.
 set ($def, $config)
 Unconditionally saves a definition object to the cache.
 replace ($def, $config)
 Replace an object in the cache.
 get ($config)
 Retrieves a definition object from the cache.
 remove ($config)
 Removes a definition object to the cache.
 flush ($config)
 Clears all objects from cache.
 cleanup ($config)
 Clears all expired (older version or revision) objects from cache.

Data Fields

 $type

Detailed Description

Abstract class representing Definition cache managers that implements useful common methods and is a factory.

Todo:

Create a separate maintenance file advanced users can use to cache their custom HTMLDefinition, which can be loaded via a configuration directive

Implement memcached

Definition at line 11 of file DefinitionCache.php.

Constructor & Destructor Documentation

HTMLPurifier_DefinitionCache::__construct (   $type)
Parameters
$nameType of definition objects this instance of the cache will handle.

Definition at line 20 of file DefinitionCache.php.

References $type.

{
$this->type = $type;
}

Member Function Documentation

HTMLPurifier_DefinitionCache::add (   $def,
  $config 
)
abstract
HTMLPurifier_DefinitionCache::checkDefType (   $def)

Checks if a definition's type jives with the cache's type.

Note
Throws an error on failure
Parameters
$defDefinition object to check
Returns
Boolean true if good, false if not

Definition at line 60 of file DefinitionCache.php.

Referenced by HTMLPurifier_DefinitionCache_Serializer\add(), HTMLPurifier_DefinitionCache_Serializer\replace(), and HTMLPurifier_DefinitionCache_Serializer\set().

{
if ($def->type !== $this->type) {
trigger_error("Cannot use definition of type {$def->type} in cache for {$this->type}");
return false;
}
return true;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache::cleanup (   $config)
abstract

Clears all expired (older version or revision) objects from cache.

Note
Be carefuly implementing this method as flush. Flush must not interfere with other Definition types, and cleanup() should not be repeatedly called by userland code.

Reimplemented in HTMLPurifier_DefinitionCache_Decorator, HTMLPurifier_DefinitionCache_Serializer, and HTMLPurifier_DefinitionCache_Null.

HTMLPurifier_DefinitionCache::flush (   $config)
abstract
HTMLPurifier_DefinitionCache::generateKey (   $config)

Generates a unique identifier for a particular configuration.

Parameters
Instanceof HTMLPurifier_Config

Definition at line 28 of file DefinitionCache.php.

Referenced by HTMLPurifier_DefinitionCache_Decorator_Memory\add(), HTMLPurifier_DefinitionCache_Serializer\generateFilePath(), HTMLPurifier_DefinitionCache_Decorator_Memory\get(), HTMLPurifier_DefinitionCache_Decorator_Memory\replace(), and HTMLPurifier_DefinitionCache_Decorator_Memory\set().

{
return $config->version . ',' . // possibly replace with function calls
$config->getBatchSerial($this->type) . ',' .
$config->get($this->type . '.DefinitionRev');
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache::get (   $config)
abstract
HTMLPurifier_DefinitionCache::isOld (   $key,
  $config 
)

Tests whether or not a key is old with respect to the configuration's version and revision number.

Parameters
$keyKey to test
$configInstance of HTMLPurifier_Config to test against

Definition at line 40 of file DefinitionCache.php.

Referenced by HTMLPurifier_DefinitionCache_Serializer\cleanup().

{
if (substr_count($key, ',') < 2) return true;
list($version, $hash, $revision) = explode(',', $key, 3);
$compare = version_compare($version, $config->version);
// version mismatch, is always old
if ($compare != 0) return true;
// versions match, ids match, check revision number
if (
$hash == $config->getBatchSerial($this->type) &&
$revision < $config->get($this->type . '.DefinitionRev')
) return true;
return false;
}

+ Here is the caller graph for this function:

HTMLPurifier_DefinitionCache::remove (   $config)
abstract
HTMLPurifier_DefinitionCache::replace (   $def,
  $config 
)
abstract
HTMLPurifier_DefinitionCache::set (   $def,
  $config 
)
abstract

Field Documentation

HTMLPurifier_DefinitionCache::$type

The documentation for this class was generated from the following file: