ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
XML_RPC2_CachedClient Class Reference
+ Collaboration diagram for XML_RPC2_CachedClient:

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

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

Private Member Functions

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

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

◆ __construct()

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.

References $options.

157  {
158  if (isset($options['cacheOptions'])) {
159  $array = $options['cacheOptions'];
160  if (isset($array['defaultCacheGroup'])) {
161  $this->_defaultCacheGroup = $array['defaultCacheGroup'];
162  unset($array['defaultCacheGroup']); // this is a "non standard" option for Cache_Lite
163  }
164  if (isset($array['cachedMethods'])) {
165  $this->_cachedMethods = $array['cachedMethods'];
166  unset($array['cachedMethods']); // this is a "non standard" option for Cache_Lite
167  }
168  if (isset($array['notCachedMethods'])) {
169  $this->_notCachedMethods = $array['notCachedMethods'];
170  unset($array['notCachedMethods']); // this is a "non standard" option for Cache_Lite
171  }
172  if (isset($array['cacheByDefault'])) {
173  $this->_cacheByDefault = $array['cacheByDefault'];
174  unset($array['CacheByDefault']); // this is a "non standard" option for Cache_Lite
175  }
176  $array['automaticSerialization'] = false; // datas are already serialized in this class
177  if (!isset($array['lifetime'])) {
178  $array['lifetime'] = 3600; // we need a default lifetime
179  }
180  unset($options['cacheOptions']); // this is a "non standard" option for XML/RPC2/Client
181  } else { // no cache options ?
182  $array = array(
183  'lifetime' => 3600, // we need a default lifetime
184  'automaticSerialization' => false // datas are already serialized in this class
185  );
186  }
187  if (isset($options['cacheDebug'])) {
188  $this->_cacheDebug = $options['cacheDebug'];
189  unset($options['cacheDebug']); // this a "non standard" option for XML/RPC2/Client
190  }
191  $this->_cacheOptions = $array;
192  $this->_cacheObject = new Cache_Lite($this->_cacheOptions);
193  $this->_options = $options;
194  $this->_uri = $uri;
195  }
if(!is_array($argv)) $options

Member Function Documentation

◆ __call()

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, $result, _makeCacheId___(), and _workWithoutCache___().

231  {
232  if (!isset($this->_cacheObject)) {
233  $this->_cacheObject = new Cache_Lite($this->_cacheOptions);
234  }
235  if (in_array($methodName, $this->_notCachedMethods)) {
236  // if the called method is listed in _notCachedMethods => no cache
237  if ($this->_cacheDebug) {
238  print "CACHE DEBUG : the called method is listed in _notCachedMethods => no cache !\n";
239  }
240  return $this->_workWithoutCache___($methodName, $parameters);
241  }
242  if (!($this->_cacheByDefault)) {
243  if ((!(isset($this->_cachedMethods[$methodName]))) and (!(in_array($methodName, $this->_cachedMethods)))) {
244  // if cache is not on by default and if the called method is not described in _cachedMethods array
245  // => no cache
246  if ($this->_cacheDebug) {
247  print "CACHE DEBUG : cache is not on by default and the called method is not listed in _cachedMethods => no cache !\n";
248  }
249  return $this->_workWithoutCache___($methodName, $parameters);
250  }
251  }
252  if (isset($this->_cachedMethods[$methodName])) {
253  if ($this->_cachedMethods[$methodName] == -1) {
254  // if a method is described with a lifetime value of -1 => no cache
255  if ($this->_cacheDebug) {
256  print "CACHE DEBUG : called method has a -1 lifetime value => no cache !\n";
257  }
258  return $this->_workWithoutCache___($methodName, $parameters);
259  }
260  // if a method is described with a specific (and <> -1) lifetime
261  // => we fix this new lifetime
262  $this->_cacheObject->setLifetime($this->_cachedMethods[$methodName]);
263  } else {
264  // there is no specific lifetime, let's use the default one
265  $this->_cacheObject->setLifetime($this->_cacheOptions['lifetime']);
266  }
267  $cacheId = $this->_makeCacheId___($methodName, $parameters);
268  $data = $this->_cacheObject->get($cacheId, $this->_defaultCacheGroup);
269  if (is_string($data)) {
270  // cache is hit !
271  if ($this->_cacheDebug) {
272  print "CACHE DEBUG : cache is hit !\n";
273  }
274  return unserialize($data);
275  }
276  // the cache is not hit, let's call the "real" XML_RPC client
277  if ($this->_cacheDebug) {
278  print "CACHE DEBUG : cache is not hit !\n";
279  }
280  $result = $this->_workWithoutCache___($methodName, $parameters);
281  $this->_cacheObject->save(serialize($result)); // save in cache for next time...
282  return $result;
283  }
_workWithoutCache___($methodName, $parameters)
Do the real call if no cache available.
$result
_makeCacheId___($methodName, $parameters)
make a cache id depending on method called (and corresponding parameters) but depending on "environne...
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
+ Here is the call graph for this function:

◆ _makeCacheId___()

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___().

323  {
324  return md5($methodName . serialize($parameters) . serialize($this->_uri) . serialize($this->_options));
325  }
+ Here is the caller graph for this function:

◆ _workWithoutCache___()

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 XML_RPC2_Client\create().

Referenced by __call().

299  {
300  if (!(isset($this->_clientObject))) {
301  // If the XML_RPC2_Client object is not available, let's build it
302  require_once('XML/RPC2/Client.php');
303  $this->_clientObject = XML_RPC2_Client::create($this->_uri, $this->_options);
304  }
305  // the real function call...
306  return call_user_func_array(array($this->_clientObject, $methodName), $parameters);
307  }
static create($uri, $options=array())
Factory method to select, create and return a XML_RPC2_Client backend.
Definition: Client.php:205
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clean___()

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.

355  {
356  $this->_cacheObject->clean($this->_defaultCacheGroup, 'ingroup');
357  }

◆ create()

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.

References $options.

211  {
212  return new XML_RPC2_CachedClient($uri, $options);
213  }
if(!is_array($argv)) $options

◆ dropCacheFile___()

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___().

340  {
341  $id = $this->_makeCacheId___($methodName, $parameters);
342  $this->_cacheObject->remove($id, $this->_defaultCacheGroup);
343  }
_makeCacheId___($methodName, $parameters)
make a cache id depending on method called (and corresponding parameters) but depending on "environne...
+ Here is the call graph for this function:

Field Documentation

◆ $_cacheByDefault

XML_RPC2_CachedClient::$_cacheByDefault = true
private

Definition at line 115 of file CachedClient.php.

◆ $_cacheDebug

XML_RPC2_CachedClient::$_cacheDebug = false
private

Definition at line 143 of file CachedClient.php.

◆ $_cachedMethods

XML_RPC2_CachedClient::$_cachedMethods = array()
private

Definition at line 99 of file CachedClient.php.

◆ $_cacheObject

XML_RPC2_CachedClient::$_cacheObject = null
private

Definition at line 122 of file CachedClient.php.

◆ $_cacheOptions

XML_RPC2_CachedClient::$_cacheOptions = array()
private

Definition at line 87 of file CachedClient.php.

◆ $_clientObject

XML_RPC2_CachedClient::$_clientObject = null
private

Definition at line 129 of file CachedClient.php.

◆ $_debug

XML_RPC2_CachedClient::$_debug = false
private

Definition at line 80 of file CachedClient.php.

◆ $_defaultCacheGroup

XML_RPC2_CachedClient::$_defaultCacheGroup = 'xml_rpc2_client'
private

Definition at line 136 of file CachedClient.php.

◆ $_notCachedMethods

XML_RPC2_CachedClient::$_notCachedMethods = array()
private

Definition at line 108 of file CachedClient.php.

◆ $_options

XML_RPC2_CachedClient::$_options
private

Definition at line 66 of file CachedClient.php.

◆ $_uri

XML_RPC2_CachedClient::$_uri
private

Definition at line 73 of file CachedClient.php.


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