Drupal 8  8.0.2
CacheCollector Class Reference
Inheritance diagram for CacheCollector:

Public Member Functions

 __construct ($cid, CacheBackendInterface $cache, LockBackendInterface $lock, array $tags=array())
 
 has ($key)
 
 get ($key)
 
 set ($key, $value)
 
 delete ($key)
 
 reset ()
 
 clear ()
 
 destruct ()
 

Protected Member Functions

 getCid ()
 
 persist ($key, $persist=TRUE)
 
 resolveCacheMiss ($key)
 
 updateCache ($lock=TRUE)
 
 normalizeLockName ($cid)
 
 lazyLoadCache ()
 
 invalidateCache ()
 

Protected Attributes

 $cid
 
 $tags
 
 $cache
 
 $lock
 
 $keysToPersist = array()
 
 $keysToRemove = array()
 
 $storage = array()
 
 $cacheCreated
 
 $cacheInvalidated = FALSE
 
 $cacheLoaded = FALSE
 

Detailed Description

Default implementation for CacheCollectorInterface.

By default, the class accounts for caches where calling functions might request keys that won't exist even after a cache rebuild. This prevents situations where a cache rebuild would be triggered over and over due to a 'missing' item. These cases are stored internally as a value of NULL. This means that the CacheCollector::get() method must be overridden if caching data where the values can legitimately be NULL, and where CacheCollector->has() needs to correctly return (equivalent to array_key_exists() vs. isset()). This should not be necessary in the majority of cases.

Constructor & Destructor Documentation

__construct (   $cid,
CacheBackendInterface  $cache,
LockBackendInterface  $lock,
array  $tags = array() 
)

Constructs a CacheCollector object.

Parameters
string$cidThe cid for the array being cached.
\Drupal\Core\Cache\CacheBackendInterface$cacheThe cache backend.
\Drupal\Core\Lock\LockBackendInterface$lockThe lock backend.
array$tags(optional) The tags to specify for the cache item.

References Drupal\cache(), and Drupal\lock().

Here is the call graph for this function:

Member Function Documentation

clear ( )

{Clears the collected cache entry.}

Implements CacheCollectorInterface.

References Drupal\cache(), CacheCollector\getCid(), Cache\invalidateTags(), and CacheCollector\reset().

Here is the call graph for this function:

delete (   $key)

{Deletes the element.It depends on the specific case and implementation whether this has a permanent effect or if it just affects the current request.

Parameters
string$keyKey that identifies the data.
}

Implements CacheCollectorInterface.

References CacheCollector\invalidateCache(), and CacheCollector\lazyLoadCache().

Here is the call graph for this function:

destruct ( )

{Performs destruct operations.}

Implements DestructableInterface.

References CacheCollector\updateCache().

Here is the call graph for this function:

get (   $key)

{Gets value from the cache.

Parameters
string$keyKey that identifies the data.
Returns
mixed The corresponding cache data.
}

Implements CacheCollectorInterface.

References CacheCollector\lazyLoadCache(), and CacheCollector\resolveCacheMiss().

Here is the call graph for this function:

getCid ( )
protected

Gets the cache ID.

Returns
string

Referenced by CacheCollector\clear(), CacheCollector\invalidateCache(), and CacheCollector\updateCache().

Here is the caller graph for this function:

has (   $key)

{Returns whether data exists for this key.

Parameters
string$keyKey that identifies the data.
}

Implements CacheCollectorInterface.

invalidateCache ( )
protected

Invalidate the cache.

References Drupal\cache(), and CacheCollector\getCid().

Referenced by CacheCollector\delete(), and CacheCollector\set().

Here is the call graph for this function:

Here is the caller graph for this function:

lazyLoadCache ( )
protected

Loads the cache if not already done.

References Drupal\cache().

Referenced by CacheCollector\delete(), CacheCollector\get(), and CacheCollector\set().

Here is the call graph for this function:

Here is the caller graph for this function:

normalizeLockName (   $cid)
protected

Normalizes a cache ID in order to comply with database limitations.

Parameters
string$cidThe passed in cache ID.
Returns
string An ASCII-encoded cache ID that is at most 255 characters long.

References Crypt\hashBase64().

Referenced by CacheCollector\updateCache().

Here is the call graph for this function:

Here is the caller graph for this function:

persist (   $key,
  $persist = TRUE 
)
protected

Flags an offset value to be written to the persistent cache.

Parameters
string$keyThe key that was requested.
bool$persist(optional) Whether the offset should be persisted or not, defaults to TRUE. When called with $persist = FALSE the offset will be unflagged so that it will not be written at the end of the request.

Referenced by ThemeRegistry\__construct(), AliasWhitelist\loadMenuPathRoots(), CacheCollectorHelper\resolveCacheMiss(), MenuActiveTrail\resolveCacheMiss(), LibraryDiscoveryCollector\resolveCacheMiss(), AliasWhitelist\resolveCacheMiss(), ThemeRegistry\resolveCacheMiss(), LocaleLookup\resolveCacheMiss(), and CacheCollectorHelper\set().

Here is the caller graph for this function:

reset ( )

{Resets the local cache.Does not clear the persistent cache.}

Implements CacheCollectorInterface.

Referenced by CacheCollector\clear(), and MenuActiveTrail\getActiveLink().

Here is the caller graph for this function:

resolveCacheMiss (   $key)
abstractprotected

Resolves a cache miss.

When an offset is not found in the object, this is treated as a cache miss. This method allows classes using this implementation to look up the actual value and allow it to be cached.

Parameters
string$keyThe offset that was requested.
Returns
mixed The value of the offset, or NULL if no value was found.

Referenced by CacheCollector\get().

Here is the caller graph for this function:

set (   $key,
  $value 
)

Implements ::set().

This is not persisted by default. In practice this means that setting a value will only apply while the object is in scope and will not be written back to the persistent cache. This follows a similar pattern to static vs. persistent caching in procedural code. Extending classes may wish to alter this behavior, for example by adding a call to persist().

Implements CacheCollectorInterface.

References CacheCollector\invalidateCache(), and CacheCollector\lazyLoadCache().

Here is the call graph for this function:

updateCache (   $lock = TRUE)
protected

Writes a value to the persistent cache immediately.

Parameters
bool$lock(optional) Whether to acquire a lock before writing to cache. Defaults to TRUE.

References Drupal\cache(), CacheCollector\getCid(), Drupal\lock(), CacheCollector\normalizeLockName(), and Cache\PERMANENT.

Referenced by CacheCollector\destruct().

Here is the call graph for this function:

Here is the caller graph for this function:


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