Drupal 8  8.0.2
PhpBackend Class Reference
Inheritance diagram for PhpBackend:

Public Member Functions

 __construct ($bin, CacheTagsChecksumInterface $checksum_provider)
 
 get ($cid, $allow_invalid=FALSE)
 
 setMultiple (array $items)
 
 getMultiple (&$cids, $allow_invalid=FALSE)
 
 set ($cid, $data, $expire=Cache::PERMANENT, array $tags=array())
 
 delete ($cid)
 
 deleteMultiple (array $cids)
 
 deleteAll ()
 
 invalidate ($cid)
 
 invalidateMultiple (array $cids)
 
 invalidateAll ()
 
 garbageCollection ()
 
 removeBin ()
 

Protected Member Functions

 getByHash ($cidhash, $allow_invalid=FALSE)
 
 prepareItem ($cache, $allow_invalid)
 
 invalidatebyHash ($cidhash)
 
 writeItem ($cidhash,\stdClass $item)
 
 storage ()
 
 normalizeCid ($cid)
 

Protected Attributes

 $bin
 
 $cache = array()
 
 $checksumProvider
 

Additional Inherited Members

- Data Fields inherited from CacheBackendInterface
const CACHE_PERMANENT = -1
 

Detailed Description

Defines a PHP cache implementation.

Stores cache items in a PHP file using a storage that implements Drupal.

This is fast because of PHP's opcode caching mechanism. Once a file's content is stored in PHP's opcode cache, including it doesn't require reading the contents from a filesystem. Instead, PHP will use the already compiled opcodes stored in memory.

Constructor & Destructor Documentation

__construct (   $bin,
CacheTagsChecksumInterface  $checksum_provider 
)

Constructs a PhpBackend object.

Parameters
string$binThe cache bin for which the object is created.
\Drupal\Core\Cache\CacheTagsChecksumInterface$checksum_providerThe cache tags checksum provider.

Member Function Documentation

delete (   $cid)

{Deletes an item from the cache.If the cache item is being deleted because it is no longer "fresh", you may consider using invalidate() instead. This allows callers to retrieve the invalid item by calling get() with $allow_invalid set to TRUE. In some cases an invalid item may be acceptable rather than having to rebuild the cache.

Parameters
string$cidThe cache ID to delete.
See Also
::invalidate()
::deleteMultiple()
::deleteAll()
}

Implements CacheBackendInterface.

References PhpBackend\normalizeCid(), and PhpBackend\storage().

Here is the call graph for this function:

deleteAll ( )

{Deletes all cache items in a bin.

See Also
::invalidateAll()
::delete()
::deleteMultiple()
}

Implements CacheBackendInterface.

References PhpBackend\storage().

Here is the call graph for this function:

deleteMultiple ( array  $cids)

{Deletes multiple items from the cache.If the cache items are being deleted because they are no longer "fresh", you may consider using invalidateMultiple() instead. This allows callers to retrieve the invalid items by calling get() with $allow_invalid set to TRUE. In some cases an invalid item may be acceptable rather than having to rebuild the cache.

Parameters
array$cidsAn array of cache IDs to delete.
See Also
::invalidateMultiple()
::delete()
::deleteAll()
}

Implements CacheBackendInterface.

garbageCollection ( )

{Performs garbage collection on a cache bin.The backend may choose to delete expired or invalidated items.}

Implements CacheBackendInterface.

get (   $cid,
  $allow_invalid = FALSE 
)

{Returns data from the persistent cache.

Parameters
string$cidThe cache ID of the data to retrieve.
bool$allow_invalid(optional) If TRUE, a cache item may be returned even if it is expired or has been invalidated. Such items may sometimes be preferred, if the alternative is recalculating the value stored in the cache, especially if another concurrent request is already recalculating the same value. The "valid" property of the returned object indicates whether the item is valid or not. Defaults to FALSE.
Returns
object|false The cache item or FALSE on failure.
See Also
::getMultiple()
}

Implements CacheBackendInterface.

References PhpBackend\getByHash(), and PhpBackend\normalizeCid().

Here is the call graph for this function:

getByHash (   $cidhash,
  $allow_invalid = FALSE 
)
protected

Fetch a cache item using a hashed cache ID.

Parameters
string$cidhashThe hashed version of the original cache ID after being normalized.
bool$allow_invalid(optional) If TRUE, a cache item may be returned even if it is expired or has been invalidated.
Returns
bool|mixed

References PhpBackend\$cache, PhpBackend\prepareItem(), and PhpBackend\storage().

Referenced by PhpBackend\get(), and PhpBackend\invalidatebyHash().

Here is the call graph for this function:

Here is the caller graph for this function:

getMultiple ( $cids,
  $allow_invalid = FALSE 
)

{Returns data from the persistent cache when given an array of cache IDs.

Parameters
array$cidsAn array of cache IDs for the data to retrieve. This is passed by reference, and will have the IDs successfully returned from cache removed.
bool$allow_invalid(optional) If TRUE, cache items may be returned even if they have expired or been invalidated. Such items may sometimes be preferred, if the alternative is recalculating the value stored in the cache, especially if another concurrent thread is already recalculating the same value. The "valid" property of the returned objects indicates whether the items are valid or not. Defaults to FALSE.
Returns
array An array of cache item objects indexed by cache ID.
See Also
::get()
}

Implements CacheBackendInterface.

invalidate (   $cid)

{Marks a cache item as invalid.Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.

Parameters
string$cidThe cache ID to invalidate.
See Also
::delete()
::invalidateMultiple()
::invalidateAll()
}

Implements CacheBackendInterface.

References PhpBackend\invalidatebyHash(), and PhpBackend\normalizeCid().

Referenced by PhpBackend\invalidateMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

invalidateAll ( )

{Marks all cache items as invalid.Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.

See Also
::deleteAll()
::invalidate()
::invalidateMultiple()
}

Implements CacheBackendInterface.

References PhpBackend\invalidatebyHash(), and PhpBackend\storage().

Here is the call graph for this function:

invalidatebyHash (   $cidhash)
protected

Invalidate one cache item.

Parameters
string$cidhashThe hashed version of the original cache ID after being normalized.

References PhpBackend\getByHash(), and PhpBackend\writeItem().

Referenced by PhpBackend\invalidate(), and PhpBackend\invalidateAll().

Here is the call graph for this function:

Here is the caller graph for this function:

invalidateMultiple ( array  $cids)

{Marks cache items as invalid.Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.

Parameters
string[]$cids An array of cache IDs to invalidate.
See Also
::deleteMultiple()
::invalidate()
::invalidateAll()
}

Implements CacheBackendInterface.

References PhpBackend\invalidate().

Here is the call graph for this function:

normalizeCid (   $cid)
protected

Ensures a normalized cache ID.

Parameters
string$cidThe passed in cache ID.
Returns
string A normalized cache ID.

References Crypt\hashBase64().

Referenced by PhpBackend\delete(), PhpBackend\get(), PhpBackend\invalidate(), and PhpBackend\set().

Here is the call graph for this function:

Here is the caller graph for this function:

prepareItem (   $cache,
  $allow_invalid 
)
protected

Prepares a cached item.

Checks that items are either permanent or did not expire, and returns data as appropriate.

Parameters
object$cacheAn item loaded from cache_get() or cache_get_multiple().
bool$allow_invalidIf FALSE, the method returns FALSE if the cache item is not valid.
Returns
mixed The item with data as appropriate or FALSE if there is no valid item to load.

References PhpBackend\$cache, and Cache\PERMANENT.

Referenced by PhpBackend\getByHash().

Here is the caller graph for this function:

removeBin ( )

{Remove a cache bin.}

Implements CacheBackendInterface.

References Drupal\cache(), and PhpBackend\storage().

Here is the call graph for this function:

set (   $cid,
  $data,
  $expire = Cache::PERMANENT,
array  $tags = array() 
)

{Stores data in the persistent cache.Core cache implementations set the created time on cache item with microtime(TRUE) rather than REQUEST_TIME_FLOAT, because the created time of cache items should match when they are created, not when the request started. Apart from being more accurate, this increases the chance an item will legitimately be considered valid.

Parameters
string$cidThe cache ID of the data to store.
mixed$dataThe data to store in the cache. Some storage engines only allow objects up to a maximum of 1MB in size to be stored by default. When caching large arrays or similar, take care to ensure $data does not exceed this size.
int$expireOne of the following values:
  • CacheBackendInterface::CACHE_PERMANENT: Indicates that the item should not be removed unless it is deleted explicitly.
  • A Unix timestamp: Indicates that the item will be considered invalid after this time, i.e. it will not be returned by get() unless $allow_invalid has been set to TRUE. When the item has expired, it may be permanently deleted by the garbage collector at any time.
array$tagsAn array of tags to be stored with the cache item. These should normally identify objects used to build the cache item, which should trigger cache invalidation when updated. For example if a cached item represents a node, both the node ID and the author's user ID might be passed in as tags. For example array('node' => array(123), 'user' => array(92)).
See Also
::get()
::getMultiple()
}

Implements CacheBackendInterface.

References PhpBackend\normalizeCid(), and PhpBackend\writeItem().

Referenced by PhpBackend\setMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

setMultiple ( array  $items)

{Store multiple items in the persistent cache.

Parameters
array$itemsAn array of cache items, keyed by cid. In the form:
$items = array(
$cid => array(
// Required, will be automatically serialized if not a string.
'data' => $data,
// Optional, defaults to CacheBackendInterface::CACHE_PERMANENT.
// (optional) The cache tags for this item, see CacheBackendInterface::set().
'tags' => array(),
),
);
}

Implements CacheBackendInterface.

References CacheBackendInterface\CACHE_PERMANENT, and PhpBackend\set().

Here is the call graph for this function:

storage ( )
protected

Gets the PHP code storage object to use.

Returns

References PhpStorageFactory\get().

Referenced by PhpBackend\delete(), PhpBackend\deleteAll(), PhpBackend\getByHash(), PhpBackend\invalidateAll(), PhpBackend\removeBin(), and PhpBackend\writeItem().

Here is the call graph for this function:

Here is the caller graph for this function:

writeItem (   $cidhash,
\stdClass  $item 
)
protected

Writes a cache item to PhpStorage.

Parameters
string$cidhashThe hashed version of the original cache ID after being normalized.
\stdClass$itemThe cache item to store.

References PhpBackend\storage().

Referenced by PhpBackend\invalidatebyHash(), and PhpBackend\set().

Here is the call graph for this function:

Here is the caller graph for this function:

Field Documentation

$cache = array()
protected

Array to store cache objects.

Referenced by PhpBackend\getByHash(), and PhpBackend\prepareItem().


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