Elgg  Version 3.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Elgg\Cache\LRUCache Class Reference

Least Recently Used Cache. More...

Inheritance diagram for Elgg\Cache\LRUCache:
Elgg\Cache\QueryCache

Public Member Functions

 __construct ($size)
 Create a LRU Cache. More...
 
 get ($key, $default=null)
 Get the value cached with this key. More...
 
 set ($key, $value)
 Add something to the cache. More...
 
 size ()
 Get the number of elements in the cache. More...
 
 containsKey ($key)
 Does the cache contain an element with this key. More...
 
 remove ($key)
 Remove the element with this key. More...
 
 clear ()
 Clear the cache. More...
 
 offsetSet ($key, $value)
 Assigns a value for the specified key. More...
 
 offsetGet ($key)
 Get the value for specified key. More...
 
 offsetUnset ($key)
 Unsets a key. More...
 
 offsetExists ($key)
 Does key exist? More...
 

Protected Member Functions

 recordAccess ($key)
 Moves the element from current position to end of array. More...
 

Protected Attributes

 $maximumSize
 
 $data = []
 

Detailed Description

Least Recently Used Cache.

A fixed sized cache that removes the element used last when it reaches its size limit.

Based on https://github.com/cash/LRUCache

Definition at line 18 of file LRUCache.php.

Constructor & Destructor Documentation

Elgg\Cache\LRUCache::__construct (   $size)

Create a LRU Cache.

Parameters
int$sizeThe size of the cache
Exceptions

Definition at line 35 of file LRUCache.php.

Member Function Documentation

Elgg\Cache\LRUCache::clear ( )

Clear the cache.

Returns
void

Definition at line 120 of file LRUCache.php.

Elgg\Cache\LRUCache::containsKey (   $key)

Does the cache contain an element with this key.

Parameters
int | string$keyThe key
Returns
boolean

Definition at line 95 of file LRUCache.php.

Elgg\Cache\LRUCache::get (   $key,
  $default = null 
)

Get the value cached with this key.

Parameters
int | string$keyThe key. Strings that are ints are cast to ints.
mixed$defaultThe value to be returned if key not found. (Optional)
Returns
mixed

Definition at line 49 of file LRUCache.php.

Elgg\Cache\LRUCache::offsetExists (   $key)

Does key exist?

See also
::offsetExists()
Parameters
int | string$keyA key to check for.
Returns
boolean

Definition at line 181 of file LRUCache.php.

Elgg\Cache\LRUCache::offsetGet (   $key)

Get the value for specified key.

See also
::offsetGet()
Parameters
int | string$keyThe key to retrieve.
Returns
mixed

Definition at line 157 of file LRUCache.php.

Elgg\Cache\LRUCache::offsetSet (   $key,
  $value 
)

Assigns a value for the specified key.

See also
::offsetSet()
Parameters
int | string$keyThe key to assign the value to.
mixed$valueThe value to set.
Returns
void

Definition at line 145 of file LRUCache.php.

Elgg\Cache\LRUCache::offsetUnset (   $key)

Unsets a key.

See also
::offsetUnset()
Parameters
int | string$keyThe key to unset.
Returns
void

Definition at line 169 of file LRUCache.php.

Elgg\Cache\LRUCache::recordAccess (   $key)
protected

Moves the element from current position to end of array.

Parameters
int | string$keyThe key
Returns
void

Definition at line 130 of file LRUCache.php.

Elgg\Cache\LRUCache::remove (   $key)

Remove the element with this key.

Parameters
int | string$keyThe key
Returns
mixed Value or null if not set

Definition at line 105 of file LRUCache.php.

Elgg\Cache\LRUCache::set (   $key,
  $value 
)

Add something to the cache.

Parameters
int | string$keyThe key. Strings that are ints are cast to ints.
mixed$valueThe value to cache
Returns
void

Definition at line 66 of file LRUCache.php.

Elgg\Cache\LRUCache::size ( )

Get the number of elements in the cache.

Returns
int

Definition at line 85 of file LRUCache.php.

Member Data Documentation

Elgg\Cache\LRUCache::$data = []
protected

Definition at line 27 of file LRUCache.php.

Elgg\Cache\LRUCache::$maximumSize
protected

Definition at line 20 of file LRUCache.php.


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