public function MemoryBackend::set in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Cache/MemoryBackend.php \Drupal\Core\Cache\MemoryBackend::set()
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 $cid: The cache ID of the data to store.
mixed $data: The 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 $expire: One 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 $tags: An 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)).
Overrides CacheBackendInterface::set
See also
\Drupal\Core\Cache\CacheBackendInterface::get()
\Drupal\Core\Cache\CacheBackendInterface::getMultiple()
2 calls to MemoryBackend::set()
- MemoryBackend::setMultiple in core/
lib/ Drupal/ Core/ Cache/ MemoryBackend.php - Store multiple items in the persistent cache.
- MemoryCounterBackend::set in core/
lib/ Drupal/ Core/ Cache/ MemoryCounterBackend.php - Stores data in the persistent cache.
1 method overrides MemoryBackend::set()
- MemoryCounterBackend::set in core/
lib/ Drupal/ Core/ Cache/ MemoryCounterBackend.php - Stores data in the persistent cache.
File
- core/
lib/ Drupal/ Core/ Cache/ MemoryBackend.php, line 109 - Contains \Drupal\Core\Cache\MemoryBackend.
Class
- MemoryBackend
- Defines a memory cache implementation.
Namespace
Drupal\Core\CacheCode
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
assert('\\Drupal\\Component\\Assertion\\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.');
$tags = array_unique($tags);
// Sort the cache tags so that they are stored consistently in the database.
sort($tags);
$this->cache[$cid] = (object) array(
'cid' => $cid,
'data' => serialize($data),
'created' => $this
->getRequestTime(),
'expire' => $expire,
'tags' => $tags,
);
}