Framework  3.9
APCUCache Class Reference

Provides a simple cacheing mechanism using the Alternative PHP Cache extension. More...

Public Member Functions

 __construct ()
 
 get ($key)
 
 put ($key, $obj, $ttl=0)
 
 invalidate ($key)
 
 invalidateMatching ($pattern)
 
 clear ()
 
 dump ()
 

Detailed Description

Provides a simple cacheing mechanism using the Alternative PHP Cache extension.

Author
Andy Green

Definition at line 294 of file cache.inc.

Constructor & Destructor Documentation

◆ __construct()

APCUCache::__construct ( )

Definition at line 296 of file cache.inc.

297  {
298  trace("Creating APCU Cache", 4);
299  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

Member Function Documentation

◆ clear()

APCUCache::clear ( )

Definition at line 335 of file cache.inc.

336  {
337  apcu_clear_cache('user');
338  }

◆ dump()

APCUCache::dump ( )

Definition at line 340 of file cache.inc.

341  {
342  echo "<table class='list'><thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>\n";
343 
344  $prefix = ConnectionManager::$dsn."_".Cache::$app_name."_";
345 
346  foreach (new APCUIterator('/.*/') as $kvp)
347  {
348  if (!startsWith($kvp['key'], $prefix)) continue;
349  $key = str_replace($prefix, "", $kvp['key']);
350  $value = htmlSafe($kvp['value']);
351 
352  echo "<tr><td><b>$key</b></td><td>{$value}</td></tr>\n";
353  }
354  echo "</tbody></table>";
355  }
static $app_name
Definition: cache.inc:44
startsWith($text, $start)
Tests whether a string starts with a given sub-string.
Definition: functions.inc:1470

◆ get()

APCUCache::get (   $key)

Definition at line 301 of file cache.inc.

302  {
303  $success = true;
304 
305  $s = apcu_fetch($key, $success);
306  if (!$success) return null;
307 
308  return unserialize($s);
309  }

◆ invalidate()

APCUCache::invalidate (   $key)

Definition at line 316 of file cache.inc.

317  {
318  return apcu_delete($key);
319  }

◆ invalidateMatching()

APCUCache::invalidateMatching (   $pattern)

Definition at line 321 of file cache.inc.

322  {
323  trace("invalidateMatching: $pattern", 3);
324  //TODO - Not working on zither - investigate
325  /*$iterator = new APCUIterator("user", $pattern);
326 
327  while($key = $iterator->key())
328  {
329  trace($key, 3);
330  Cache::invalidate($key);
331  $iterator->next();
332  }*/
333  }

◆ put()

APCUCache::put (   $key,
  $obj,
  $ttl = 0 
)

Definition at line 311 of file cache.inc.

312  {
313  return apcu_store($key, serialize($obj), $ttl);
314  }

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