本文整理汇总了PHP中Drupal\Core\Cache\CacheBackendInterface::getMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP CacheBackendInterface::getMultiple方法的具体用法?PHP CacheBackendInterface::getMultiple怎么用?PHP CacheBackendInterface::getMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Cache\CacheBackendInterface
的用法示例。
在下文中一共展示了CacheBackendInterface::getMultiple方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMultiple
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids, $allow_invalid = FALSE)
{
foreach ($cids as &$cid) {
$cid = $this->decorate($cid);
}
return $this->decorated->getMultiple($cids, $allow_invalid);
}
示例2: readMultiple
/**
* {@inheritdoc}
*/
public function readMultiple(array $names)
{
$data_to_return = array();
$cache_keys_map = $this->getCacheKeys($names);
$cache_keys = array_values($cache_keys_map);
$cached_list = $this->cache->getMultiple($cache_keys);
if (!empty($cache_keys)) {
// $cache_keys_map contains the full $name => $cache_key map, while
// $cache_keys contains just the $cache_key values that weren't found in
// the cache.
// @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple()
$names_to_get = array_keys(array_intersect($cache_keys_map, $cache_keys));
$list = $this->storage->readMultiple($names_to_get);
// Cache configuration objects that were loaded from the storage, cache
// missing configuration objects as an explicit FALSE.
$items = array();
foreach ($names_to_get as $name) {
$data = isset($list[$name]) ? $list[$name] : FALSE;
$data_to_return[$name] = $data;
$items[$cache_keys_map[$name]] = array('data' => $data);
}
$this->cache->setMultiple($items);
}
// Add the configuration objects from the cache to the list.
$cache_keys_inverse_map = array_flip($cache_keys_map);
foreach ($cached_list as $cache_key => $cache) {
$name = $cache_keys_inverse_map[$cache_key];
$data_to_return[$name] = $cache->data;
}
// Ensure that only existing configuration objects are returned, filter out
// cached information about missing objects.
return array_filter($data_to_return);
}
示例3: getMultiple
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids, $allow_invalid = FALSE)
{
// Retrieve as many cache items as possible from the fast backend. (Some
// cache entries may have been created before the last write to this cache
// bin and therefore be stale/wrong/inconsistent.)
$cids_copy = $cids;
$cache = array();
$last_write_timestamp = $this->getLastWriteTimestamp();
if ($last_write_timestamp) {
foreach ($this->fastBackend->getMultiple($cids, $allow_invalid) as $item) {
if ($item->created < $last_write_timestamp) {
$cids[array_search($item->cid, $cids_copy)] = $item->cid;
} else {
$cache[$item->cid] = $item;
}
}
}
// If there were any cache entries that were not available in the fast
// backend, retrieve them from the consistent backend and store them in the
// fast one.
if ($cids) {
foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) {
$cache[$item->cid] = $item;
$this->fastBackend->set($item->cid, $item->data);
}
}
return $cache;
}
示例4: getMultiple
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids, $allow_invalid = FALSE)
{
$cids_copy = $cids;
$cache = array();
// If we can determine the time at which the last write to the consistent
// backend occurred (we might not be able to if it has been recently
// flushed/restarted), then we can use that to validate items from the fast
// backend, so try to get those first. Otherwise, we can't assume that
// anything in the fast backend is valid, so don't even bother fetching
// from there.
$last_write_timestamp = $this->getLastWriteTimestamp();
if ($last_write_timestamp) {
// Items in the fast backend might be invalid based on their timestamp,
// but we can't check the timestamp prior to getting the item, which
// includes unserializing it. However, unserializing an invalid item can
// throw an exception. For example, a __wakeup() implementation that
// receives object properties containing references to code or data that
// no longer exists in the application's current state.
//
// Unserializing invalid data, whether it throws an exception or not, is
// a waste of time, but we only incur it while a cache invalidation has
// not yet finished propagating to all the fast backend instances.
//
// Most cache backend implementations should not wrap their internal
// get() implementations with a try/catch, because they have no reason to
// assume that their data is invalid, and doing so would mask
// unserialization errors of valid data. We do so here, only because the
// fast backend is non-authoritative, and after discarding its
// exceptions, we proceed to check the consistent (authoritative) backend
// and allow exceptions from that to bubble up.
try {
$items = $this->fastBackend->getMultiple($cids, $allow_invalid);
} catch (\Exception $e) {
$cids = $cids_copy;
$items = array();
}
// Even if items were successfully fetched from the fast backend, they
// are potentially invalid if older than the last time the bin was
// written to in the consistent backend, so only keep ones that aren't.
foreach ($items as $item) {
if ($item->created < $last_write_timestamp) {
$cids[array_search($item->cid, $cids_copy)] = $item->cid;
} else {
$cache[$item->cid] = $item;
}
}
}
// If there were any cache entries that were not available in the fast
// backend, retrieve them from the consistent backend and store them in the
// fast one.
if ($cids) {
foreach ($this->consistentBackend->getMultiple($cids, $allow_invalid) as $item) {
$cache[$item->cid] = $item;
// Don't write the cache tags to the fast backend as any cache tag
// invalidation results in an invalidation of the whole fast backend.
$this->fastBackend->set($item->cid, $item->data, $item->expire);
}
}
return $cache;
}
示例5: readMultiple
/**
* {@inheritdoc}
*/
public function readMultiple(array $names)
{
$list = array();
// The names array is passed by reference and will only contain the names of
// config object not found after the method call.
// @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple()
$cached_list = $this->cache->getMultiple($names);
if (!empty($names)) {
$list = $this->storage->readMultiple($names);
// Cache configuration objects that were loaded from the storage, cache
// missing configuration objects as an explicit FALSE.
$items = array();
foreach ($names as $name) {
$items[$name] = array('data' => isset($list[$name]) ? $list[$name] : FALSE);
}
$this->cache->setMultiple($items);
}
// Add the configuration objects from the cache to the list.
foreach ($cached_list as $name => $cache) {
$list[$name] = $cache->data;
}
// Ensure that only existing configuration objects are returned, filter out
// cached information about missing objects.
return array_filter($list);
}
示例6: getMultiple
/**
* {@inheritdoc}
*/
public function getMultiple(&$cids, $allow_invalid = FALSE)
{
$cidsCopy = $cids;
$cache = $this->cacheBackend->getMultiple($cids, $allow_invalid);
foreach ($cidsCopy as $cid) {
if (in_array($cid, $cids)) {
$this->cacheDataCollector->registerCacheMiss($this->bin, $cid);
} else {
$cacheCopy = new \StdClass();
$cacheCopy->cid = $cache[$cid]->cid;
$cacheCopy->expire = $cache[$cid]->expire;
$cacheCopy->tags = $cache[$cid]->tags;
$this->cacheDataCollector->registerCacheHit($this->bin, $cacheCopy);
}
}
return $cache;
}
示例7: getFromPersistentCache
/**
* Gets entities from the persistent cache backend.
*
* @param array|null &$ids
* If not empty, return entities that match these IDs. IDs that were found
* will be removed from the list.
*
* @return \Drupal\Core\Entity\ContentEntityInterface[]
* Array of entities from the persistent cache.
*/
protected function getFromPersistentCache(array &$ids = NULL)
{
if (!$this->entityType->isPersistentlyCacheable() || empty($ids)) {
return array();
}
$entities = array();
// Build the list of cache entries to retrieve.
$cid_map = array();
foreach ($ids as $id) {
$cid_map[$id] = $this->buildCacheId($id);
}
$cids = array_values($cid_map);
if ($cache = $this->cacheBackend->getMultiple($cids)) {
// Get the entities that were found in the cache.
foreach ($ids as $index => $id) {
$cid = $cid_map[$id];
if (isset($cache[$cid])) {
$entities[$id] = $cache[$cid]->data;
unset($ids[$index]);
}
}
}
return $entities;
}