public function D8Cache::set in Drupal 8 Cache Backport 7
1 call to D8Cache::set()
- D8CacheAttachmentsCollector::set in ./d8cache-ac.cache.inc
1 method overrides D8Cache::set()
- D8CacheAttachmentsCollector::set in ./d8cache-ac.cache.inc
File
- ./d8cache.cache.inc, line 123
Class
- D8Cache
- Defines a Drupal 8 cacheable metadata aware cache backend.
Code
public function set($cid, $data, $expire = CACHE_PERMANENT, $tags = array()) {
if (isset($this->configuration['ttl'])) {
if ($this->configuration['ttl'] == CACHE_MAX_AGE_PERMANENT) {
$expire = CACHE_PERMANENT;
}
elseif ($this->configuration['ttl'] == CACHE_PERMANENT || $this->configuration['ttl'] == CACHE_TEMPORARY) {
$expire = $this->configuration['ttl'];
}
else {
$expire = REQUEST_TIME + $this->configuration['ttl'];
}
}
if (isset($this->configuration['tags'])) {
$tags = drupal_merge_cache_tags($tags, $this->configuration['tags']);
}
if ($this->bin == 'cache_page') {
$page_cache_tags =& drupal_static('d8cache_emit_cache_tags', array());
$page_cache_max_age =& drupal_static('d8cache_emit_cache_max_age', CACHE_MAX_AGE_PERMANENT);
if (!empty($page_cache_tags)) {
$tags = drupal_merge_cache_tags($tags, $page_cache_tags);
}
$expire = $this
->mergeExpireWithMaxAge($expire, $page_cache_max_age);
}
if (is_array($data) && isset($data['#attached']) && (isset($data['#attached']['drupal_add_cache_tags']) || isset($data['#attached']['drupal_set_cache_max_age']))) {
$cacheable_metadata = drupal_get_cacheable_metadata_from_render_array($data);
if (!empty($cacheable_metadata['tags'])) {
$tags = drupal_merge_cache_tags($tags, $cacheable_metadata['tags']);
$data['#attached']['drupal_add_cache_tags'] = array(
array(
0 => $cacheable_metadata['tags'],
),
);
}
$expire = $this
->mergeExpireWithMaxAge($expire, $cacheable_metadata['max-age']);
if ($cacheable_metadata['max-age'] != CACHE_MAX_AGE_PERMANENT) {
$data['#attached']['drupal_set_cache_max_age'] = array(
array(
0 => $cacheable_metadata['max-age'],
),
);
}
}
if (empty($tags)) {
$this->backend
->set($cid, $data, $expire);
return;
}
if ($this->backend instanceof TaggableDrupalCacheInterface) {
$this->backend
->set($cid, $data, $expire, $tags);
}
else {
$checksum = $this
->getCurrentChecksum($tags);
$data = (object) array(
'd8cache_tags' => $tags,
'd8cache_checksum' => $checksum,
'd8cache_expire' => $expire,
'd8cache_data' => $data,
);
$this->backend
->set($cid, $data, $expire);
}
}