Framework  3.9
SimpleMemoryCache Class Reference

Implements a simple in-memory cache when other cacheing mechanisms are not available. More...

Public Member Functions

 SimpleMemoryCache ()
 
 get ($key)
 
 put ($key, $obj, $ttl=0)
 
 invalidate ($key)
 
 invalidateMatching ($pattern)
 
 filterKey ($key)
 Internal callback function that supports the invalidateMatching function. More...
 
 clear ()
 
 dump ()
 

Public Attributes

 $cache
 

Detailed Description

Implements a simple in-memory cache when other cacheing mechanisms are not available.

Author
Andy Green

Definition at line 162 of file cache.inc.

Member Function Documentation

◆ clear()

SimpleMemoryCache::clear ( )

Definition at line 206 of file cache.inc.

207  {
208  $this->cache = array();
209  }

◆ dump()

SimpleMemoryCache::dump ( )

Definition at line 211 of file cache.inc.

212  {
213  throw new FakoliException("Not implemented");
214  }

◆ filterKey()

SimpleMemoryCache::filterKey (   $key)

Internal callback function that supports the invalidateMatching function.

Parameters
string$keythe key to be filtered.

Definition at line 201 of file cache.inc.

202  {
203  return !preg_match("/".$this->pattern."/", $key);
204  }

◆ get()

SimpleMemoryCache::get (   $key)

Definition at line 172 of file cache.inc.

173  {
174  return $this->cache[$key];
175  }

◆ invalidate()

SimpleMemoryCache::invalidate (   $key)

Definition at line 184 of file cache.inc.

185  {
186  unset($this->cache[$key]);
187  return true;
188  }

◆ invalidateMatching()

SimpleMemoryCache::invalidateMatching (   $pattern)

Definition at line 190 of file cache.inc.

191  {
192  $this->pattern = $pattern;
193  $this->cache = arrayFilterKey($this->cache, array($this, filterKey));
194  unset($this->pattern);
195  }
filterKey($key)
Internal callback function that supports the invalidateMatching function.
Definition: cache.inc:201
arrayFilterKey( $input, $callback)
Filter an array based on applying the specified callback to the keys.
Definition: functions.inc:1752

◆ put()

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

Definition at line 177 of file cache.inc.

178  {
179  $this->cache[$key] = $obj;
180  return true;
181  // NOTE - ttl is ignored if using in-memory caching.
182  }

◆ SimpleMemoryCache()

SimpleMemoryCache::SimpleMemoryCache ( )

Definition at line 166 of file cache.inc.

167  {
168  trace("Creating Simple In-memory Cache", 4);
169  $this->cache = array();
170  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

Member Data Documentation

◆ $cache

SimpleMemoryCache::$cache

Definition at line 164 of file cache.inc.


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