PhpBackend
class PhpBackend implements CacheBackendInterface (View source)
Defines a PHP cache implementation.
Stores cache items in a PHP file using a storage that implements Drupal\Component\PhpStorage\PhpStorageInterface.
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.
Properties
| protected string | $bin | ||
| protected | $cache | Array to store cache objects. |
|
| protected CacheTagsChecksumInterface | $checksumProvider | The cache tags checksum provider. |
Methods
Constructs a PhpBackend object.
Returns data from the persistent cache.
Fetch a cache item using a hashed cache ID.
Store multiple items in the persistent cache.
Returns data from the persistent cache when given an array of cache IDs.
Prepares a cached item.
Stores data in the persistent cache.
Deletes an item from the cache.
Deletes multiple items from the cache.
Deletes all cache items in a bin.
Marks a cache item as invalid.
Invalidate one cache item.
Marks cache items as invalid.
Marks all cache items as invalid.
Performs garbage collection on a cache bin.
Remove a cache bin.
Gets the PHP code storage object to use.
Ensures a normalized cache ID.
Details
__construct(string $bin, CacheTagsChecksumInterface $checksum_provider)
Constructs a PhpBackend object.
object|false
get(string $cid, bool $allow_invalid = FALSE)
Returns data from the persistent cache.
protected bool|mixed
getByHash(string $cidhash, bool $allow_invalid = FALSE)
Fetch a cache item using a hashed cache ID.
setMultiple(array $items)
Store multiple items in the persistent cache.
array
getMultiple(array $cids, bool $allow_invalid = FALSE)
Returns data from the persistent cache when given an array of cache IDs.
protected mixed
prepareItem(object $cache, bool $allow_invalid)
Prepares a cached item.
Checks that items are either permanent or did not expire, and returns data as appropriate.
set(string $cid, mixed $data, int $expire = Cache::PERMANENT, array $tags = [])
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.
delete(string $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.
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.
deleteAll()
Deletes all cache items in a bin.
invalidate(string $cid)
Marks a cache item as invalid.
Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.
protected
invalidatebyHash(string $cidhash)
Invalidate one cache item.
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.
invalidateAll()
Marks all cache items as invalid.
Invalid items may be returned in later calls to get(), if the $allow_invalid argument is TRUE.
garbageCollection()
Performs garbage collection on a cache bin.
The backend may choose to delete expired or invalidated items.
removeBin()
Remove a cache bin.
protected
writeItem(string $cidhash, stdClass $item)
Writes a cache item to PhpStorage.
protected PhpStorageInterface
storage()
Gets the PHP code storage object to use.
protected string
normalizeCid(string $cid)
Ensures a normalized cache ID.