Framework  3.9
Cache Class Reference

The Cache class provides a simple caching interface. More...

Static Public Member Functions

static getInstance ()
 
static get ($key)
 Retrieve the specified object from the cache. More...
 
static put ($key, $obj, $ttl=0)
 Store the specified object in the cache at the specified key. More...
 
static invalidate ($key)
 Invalidates the specifed entry in the cache. More...
 
static invalidateMatching ($pattern)
 Invalidate all entries in the cache that match a specific pattern. More...
 
static clear ()
 Clear the cache, deleting all records. More...
 
static dump ()
 Output a dump of the cache for debugging purposes. More...
 

Static Public Attributes

static $instance
 
static $app_name
 

Detailed Description

The Cache class provides a simple caching interface.

If APC is installed and enabled, caching will be done through APC and will be available across page accesses. If APC is not available, a simple in-memory hash is used.

Author
Andy Green

Definition at line 41 of file cache.inc.

Member Function Documentation

◆ clear()

static Cache::clear ( )
static

Clear the cache, deleting all records.

Definition at line 141 of file cache.inc.

142  {
143  return Cache::getInstance()->clear();
144  }
static getInstance()
Definition: cache.inc:46

◆ dump()

static Cache::dump ( )
static

Output a dump of the cache for debugging purposes.

Definition at line 149 of file cache.inc.

150  {
151  return Cache::getInstance()->dump();
152  }

◆ get()

static Cache::get (   $key)
static

Retrieve the specified object from the cache.

Parameters
string$keythe key identifying the object
Returns
mixed the associated object, or null if no match was found

Definition at line 88 of file cache.inc.

89  {
91  }
static $app_name
Definition: cache.inc:44

◆ getInstance()

static Cache::getInstance ( )
static

Definition at line 46 of file cache.inc.

47  {
48  global $config;
49 
50  trace(get_class(Cache::$instance), 5);
51 
53 
54  if (array_key_exists("file_backed_cache_directory", $config))
55  {
57  }
58  else if (ini_get("apc.enabled") && PHP_SAPI !== 'cli')
59  {
60  if (PHP_MAJOR_VERSION >= 7)
61  {
63  }
64  else
65  {
66  Cache::$instance = new APCCache();
67  }
68  }
69  else if (ini_get("wincache.ucenabled") && PHP_SAPI !== 'cli')
70  {
71  Cache::$instance = new WCCache();
72  }
73  else
74  {
76  }
77 
78  Cache::$app_name = codify($config['sitename']);
79 
80  return Cache::$instance;
81  }
Provides a simple cacheing mechanism using the Alternative PHP Cache extension.
Definition: cache.inc:224
Provides a simple cacheing mechanism using the Alternative PHP Cache extension.
Definition: cache.inc:295
static $instance
Definition: cache.inc:43
Provides a simple File-backed caching implementation for when no shared memory caching extension is p...
Definition: cache.inc:445
Implements a simple in-memory cache when other cacheing mechanisms are not available.
Definition: cache.inc:163
Provides a simple cacheing mechanism using the WinCache PHP extension (for use under IIS).
Definition: cache.inc:362
codify($name)
Takes a text string and converts it into a code-compliant format, suitable for use as a variable name...
Definition: functions.inc:1399
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ invalidate()

static Cache::invalidate (   $key)
static

Invalidates the specifed entry in the cache.

This can be used to flag items in the cache that have potentially been updated by other actions. These items are removed from the cache upon invalidation. If the item has not been cached, no action is taken.

Parameters
string$keythe entry to be invalidated

Definition at line 119 of file cache.inc.

120  {
121  return Cache::getInstance()->invalidate(ConnectionManager::$dsn."_".Cache::$app_name."_".$key);
122  }

◆ invalidateMatching()

static Cache::invalidateMatching (   $pattern)
static

Invalidate all entries in the cache that match a specific pattern.

This can be used to flag items in the cache that have potentially been updated by other actions. These items are removed from the cache upon invalidation. If the item has not been cached, no action is taken.

Parameters
string$patternPCRE describing the matching keys

Definition at line 133 of file cache.inc.

134  {
135  return Cache::getInstance()->invalidateMatching("^".ConnectionManager::$dsn."_".Cache::$app_name."_".$pattern);
136  }

◆ put()

static Cache::put (   $key,
  $obj,
  $ttl = 0 
)
static

Store the specified object in the cache at the specified key.

If APC cacheing is enabled then this value will be available to subsequent script invocations, and the $ttl parameter can optionally be used to specify the time-to-live of the cache record. If APC is enabled and the TTL is not specified then the item will stay in the cache until it is invalidated. If APC is not enabled then the item will only remain in the cache for the rest of this script invocation.

Parameters
string$keythe key that the value will be cached under.
mixed$objthe object or value to be cached
integer$ttlthe time-to-live for the cache entry, in seconds

Definition at line 106 of file cache.inc.

107  {
108  return Cache::getInstance()->put(ConnectionManager::$dsn."_".Cache::$app_name."_".$key, $obj, $ttl);
109  }

Member Data Documentation

◆ $app_name

Cache::$app_name
static

Definition at line 44 of file cache.inc.

◆ $instance

Cache::$instance
static

Definition at line 43 of file cache.inc.


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