ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
XML_RPC2_CachedClient Class Reference
+ Collaboration diagram for XML_RPC2_CachedClient:

Public Member Functions

 __call ($methodName, $parameters)
 __call Catchall
 dropCacheFile___ ($methodName, $parameters)
 Drop the cache file corresponding to the given method call.
 clean___ ()
 Clean all the cache.

Static Public Member Functions

static create ($uri, $options=array())
 "Emulated Factory" method to get the same API than XML_RPC2_Client class

Protected Member Functions

 __construct ($uri, $options=array())
 Constructor.

Private Member Functions

 _workWithoutCache___ ($methodName, $parameters)
 Do the real call if no cache available.
 _makeCacheId___ ($methodName, $parameters)
 make a cache id depending on method called (and corresponding parameters) but depending on "environnement" setting too

Private Attributes

 $_options
 $_uri
 $_debug = false
 $_cacheOptions = array()
 $_cachedMethods = array()
 $_notCachedMethods = array()
 $_cacheByDefault = true
 $_cacheObject = null
 $_clientObject = null
 $_defaultCacheGroup = 'xml_rpc2_client'
 $_cacheDebug = false

Detailed Description

Definition at line 57 of file CachedClient.php.

Constructor & Destructor Documentation

XML_RPC2_CachedClient::__construct (   $uri,
  $options = array() 
)
protected

Constructor.

TODO : documentations about cache options

Parameters
stringURI for the XML-RPC server
array(optional) Associative array of options

Definition at line 156 of file CachedClient.php.

{
if (isset($options['cacheOptions'])) {
$array = $options['cacheOptions'];
if (isset($array['defaultCacheGroup'])) {
$this->_defaultCacheGroup = $array['defaultCacheGroup'];
unset($array['defaultCacheGroup']); // this is a "non standard" option for Cache_Lite
}
if (isset($array['cachedMethods'])) {
$this->_cachedMethods = $array['cachedMethods'];
unset($array['cachedMethods']); // this is a "non standard" option for Cache_Lite
}
if (isset($array['notCachedMethods'])) {
$this->_notCachedMethods = $array['notCachedMethods'];
unset($array['notCachedMethods']); // this is a "non standard" option for Cache_Lite
}
if (isset($array['cacheByDefault'])) {
$this->_cacheByDefault = $array['cacheByDefault'];
unset($array['CacheByDefault']); // this is a "non standard" option for Cache_Lite
}
$array['automaticSerialization'] = false; // datas are already serialized in this class
if (!isset($array['lifetime'])) {
$array['lifetime'] = 3600; // we need a default lifetime
}
unset($options['cacheOptions']); // this is a "non standard" option for XML/RPC2/Client
} else { // no cache options ?
$array = array(
'lifetime' => 3600, // we need a default lifetime
'automaticSerialization' => false // datas are already serialized in this class
);
}
if (isset($options['cacheDebug'])) {
$this->_cacheDebug = $options['cacheDebug'];
unset($options['cacheDebug']); // this a "non standard" option for XML/RPC2/Client
}
$this->_cacheOptions = $array;
$this->_cacheObject = new Cache_Lite($this->_cacheOptions);
$this->_options = $options;
$this->_uri = $uri;
}

Member Function Documentation

XML_RPC2_CachedClient::__call (   $methodName,
  $parameters 
)

__call Catchall

Encapsulate all the class logic :

  • determine if the cache has to be used (or not) for the called method
  • see if a cache is available for this call
  • if no cache available, really do the call and store the result for next time
Parameters
stringMethod name
arrayParameters
Returns
mixed The call result, already decoded into native types

Definition at line 230 of file CachedClient.php.

References $data, _makeCacheId___(), and _workWithoutCache___().

{
if (!isset($this->_cacheObject)) {
$this->_cacheObject = new Cache_Lite($this->_cacheOptions);
}
if (in_array($methodName, $this->_notCachedMethods)) {
// if the called method is listed in _notCachedMethods => no cache
if ($this->_cacheDebug) {
print "CACHE DEBUG : the called method is listed in _notCachedMethods => no cache !\n";
}
return $this->_workWithoutCache___($methodName, $parameters);
}
if (!($this->_cacheByDefault)) {
if ((!(isset($this->_cachedMethods[$methodName]))) and (!(in_array($methodName, $this->_cachedMethods)))) {
// if cache is not on by default and if the called method is not described in _cachedMethods array
// => no cache
if ($this->_cacheDebug) {
print "CACHE DEBUG : cache is not on by default and the called method is not listed in _cachedMethods => no cache !\n";
}
return $this->_workWithoutCache___($methodName, $parameters);
}
}
if (isset($this->_cachedMethods[$methodName])) {
if ($this->_cachedMethods[$methodName] == -1) {
// if a method is described with a lifetime value of -1 => no cache
if ($this->_cacheDebug) {
print "CACHE DEBUG : called method has a -1 lifetime value => no cache !\n";
}
return $this->_workWithoutCache___($methodName, $parameters);
}
// if a method is described with a specific (and <> -1) lifetime
// => we fix this new lifetime
$this->_cacheObject->setLifetime($this->_cachedMethods[$methodName]);
} else {
// there is no specific lifetime, let's use the default one
$this->_cacheObject->setLifetime($this->_cacheOptions['lifetime']);
}
$cacheId = $this->_makeCacheId___($methodName, $parameters);
$data = $this->_cacheObject->get($cacheId, $this->_defaultCacheGroup);
if (is_string($data)) {
// cache is hit !
if ($this->_cacheDebug) {
print "CACHE DEBUG : cache is hit !\n";
}
return unserialize($data);
}
// the cache is not hit, let's call the "real" XML_RPC client
if ($this->_cacheDebug) {
print "CACHE DEBUG : cache is not hit !\n";
}
$result = $this->_workWithoutCache___($methodName, $parameters);
$this->_cacheObject->save(serialize($result)); // save in cache for next time...
return $result;
}

+ Here is the call graph for this function:

XML_RPC2_CachedClient::_makeCacheId___ (   $methodName,
  $parameters 
)
private

make a cache id depending on method called (and corresponding parameters) but depending on "environnement" setting too

NB : The '___' at the end of the method name is to avoid collisions with XMLRPC __call()

Parameters
string$methodNamecalled method
array$parametersparameters of the called method
Returns
string cache id

Definition at line 322 of file CachedClient.php.

Referenced by __call(), and dropCacheFile___().

{
return md5($methodName . serialize($parameters) . serialize($this->_uri) . serialize($this->_options));
}

+ Here is the caller graph for this function:

XML_RPC2_CachedClient::_workWithoutCache___ (   $methodName,
  $parameters 
)
private

Do the real call if no cache available.

NB : The '___' at the end of the method name is to avoid collisions with XMLRPC __call()

Parameters
stringMethod name
arrayParameters
Returns
mixed The call result, already decoded into native types

Definition at line 298 of file CachedClient.php.

References create().

Referenced by __call().

{
if (!(isset($this->_clientObject))) {
// If the XML_RPC2_Client object is not available, let's build it
require_once('XML/RPC2/Client.php');
$this->_clientObject = XML_RPC2_Client::create($this->_uri, $this->_options);
}
// the real function call...
return call_user_func_array(array($this->_clientObject, $methodName), $parameters);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

XML_RPC2_CachedClient::clean___ ( )

Clean all the cache.

NB : The '___' at the end of the method name is to avoid collisions with XMLRPC __call()

Definition at line 354 of file CachedClient.php.

{
$this->_cacheObject->clean($this->_defaultCacheGroup, 'ingroup');
}
static XML_RPC2_CachedClient::create (   $uri,
  $options = array() 
)
static

"Emulated Factory" method to get the same API than XML_RPC2_Client class

Here, simply returns a new instance of XML_RPC2_CachedClient class

Parameters
stringURI for the XML-RPC server
string(optional) Prefix to prepend on all called functions (defaults to '')
string(optional) Proxy server URI (defaults to no proxy)

Definition at line 210 of file CachedClient.php.

Referenced by _workWithoutCache___().

{
return new XML_RPC2_CachedClient($uri, $options);
}

+ Here is the caller graph for this function:

XML_RPC2_CachedClient::dropCacheFile___ (   $methodName,
  $parameters 
)

Drop the cache file corresponding to the given method call.

NB : The '___' at the end of the method name is to avoid collisions with XMLRPC __call()

Parameters
string$methodNamecalled method
array$parametersparameters of the called method

Definition at line 339 of file CachedClient.php.

References _makeCacheId___().

{
$id = $this->_makeCacheId___($methodName, $parameters);
$this->_cacheObject->remove($id, $this->_defaultCacheGroup);
}

+ Here is the call graph for this function:

Field Documentation

XML_RPC2_CachedClient::$_cacheByDefault = true
private

Definition at line 115 of file CachedClient.php.

XML_RPC2_CachedClient::$_cacheDebug = false
private

Definition at line 143 of file CachedClient.php.

XML_RPC2_CachedClient::$_cachedMethods = array()
private

Definition at line 99 of file CachedClient.php.

XML_RPC2_CachedClient::$_cacheObject = null
private

Definition at line 122 of file CachedClient.php.

XML_RPC2_CachedClient::$_cacheOptions = array()
private

Definition at line 87 of file CachedClient.php.

XML_RPC2_CachedClient::$_clientObject = null
private

Definition at line 129 of file CachedClient.php.

XML_RPC2_CachedClient::$_debug = false
private

Definition at line 80 of file CachedClient.php.

XML_RPC2_CachedClient::$_defaultCacheGroup = 'xml_rpc2_client'
private

Definition at line 136 of file CachedClient.php.

XML_RPC2_CachedClient::$_notCachedMethods = array()
private

Definition at line 108 of file CachedClient.php.

XML_RPC2_CachedClient::$_options
private

Definition at line 66 of file CachedClient.php.

XML_RPC2_CachedClient::$_uri
private

Definition at line 73 of file CachedClient.php.


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