Drupal 8  8.0.2
DatabaseBackend Class Reference
Inheritance diagram for DatabaseBackend:

Public Member Functions

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

Protected Member Functions

 prepareItem ($cache, $allow_invalid)
 
 doSetMultiple (array $items)
 
 ensureBinExists ()
 
 catchException (\Exception $e, $table_name=NULL)
 
 normalizeCid ($cid)
 

Protected Attributes

 $bin
 
 $connection
 
 $checksumProvider
 

Additional Inherited Members

- Data Fields inherited from CacheBackendInterface
const CACHE_PERMANENT = -1
 

Detailed Description

Defines a default cache implementation.

This is Drupal's default cache implementation. It uses the database to store cached data. Each cache bin corresponds to a database table by the same name.

Constructor & Destructor Documentation

__construct ( Connection  $connection,
CacheTagsChecksumInterface  $checksum_provider,
  $bin 
)

Constructs a DatabaseBackend object.

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

Member Function Documentation

catchException ( \Exception  $e,
  $table_name = NULL 
)
protected

Act on an exception when cache might be stale.

If the table does not yet exist, that's fine, but if the table exists and yet the query failed, then the cache is stale and the exception needs to propagate.

Parameters
$eThe exception.
string | null$table_nameThe table name. Defaults to $this->bin.
Exceptions
\Exception

Referenced by DatabaseBackend\deleteAll(), DatabaseBackend\deleteMultiple(), DatabaseBackend\invalidateAll(), DatabaseBackend\invalidateMultiple(), and DatabaseBackend\removeBin().

Here is the caller graph for this function:

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 DatabaseBackend\deleteMultiple().

Here is the call graph for this function:

deleteAll ( )

{Deletes all cache items in a bin.

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

Implements CacheBackendInterface.

References DatabaseBackend\catchException(), and DatabaseBackend\ensureBinExists().

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.

References DatabaseBackend\catchException(), and DatabaseBackend\ensureBinExists().

Referenced by DatabaseBackend\delete().

Here is the call graph for this function:

Here is the caller graph for this function:

doSetMultiple ( array  $items)
protected

Stores multiple items in the persistent cache.

Parameters
array$itemsAn array of cache items, keyed by cid.
See Also
::setMultiple()

References CacheBackendInterface\CACHE_PERMANENT, and DatabaseBackend\normalizeCid().

Referenced by DatabaseBackend\setMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

ensureBinExists ( )
protected

Check if the cache bin exists and create it if not.

References DatabaseBackend\schemaDefinition().

Referenced by DatabaseBackend\deleteAll(), DatabaseBackend\deleteMultiple(), and DatabaseBackend\setMultiple().

Here is the call graph for this function:

Here is the caller graph for this function:

garbageCollection ( )

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

Implements CacheBackendInterface.

References Cache\PERMANENT.

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 DatabaseBackend\getMultiple().

Here is the call 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.

References DatabaseBackend\normalizeCid(), and DatabaseBackend\prepareItem().

Referenced by DatabaseBackend\get().

Here is the call graph for this function:

Here is the caller graph for this function:

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 DatabaseBackend\invalidateMultiple().

Here is the call 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 DatabaseBackend\catchException().

Here is the call 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 DatabaseBackend\catchException().

Referenced by DatabaseBackend\invalidate().

Here is the call graph for this function:

Here is the caller graph for this function:

normalizeCid (   $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 DatabaseBackend\doSetMultiple(), and DatabaseBackend\getMultiple().

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 unserializes 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|false The item with data unserialized as appropriate and a property indicating whether the item is valid, or FALSE if there is no valid item to load.

References Cache\PERMANENT.

Referenced by DatabaseBackend\getMultiple().

Here is the caller graph for this function:

removeBin ( )

{Remove a cache bin.}

Implements CacheBackendInterface.

References DatabaseBackend\catchException().

Here is the call graph for this function:

schemaDefinition ( )

Defines the schema for the {cache_*} bin tables.

References Cache\PERMANENT.

Referenced by DatabaseBackend\ensureBinExists().

Here is the caller 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 DatabaseBackend\setMultiple().

Here is the call 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 DatabaseBackend\doSetMultiple(), and DatabaseBackend\ensureBinExists().

Referenced by DatabaseBackend\set().

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: