public static CacheableMetadata::createFromObject($object)
Creates a CacheableMetadata object from a depended object.
\Drupal\Core\Cache\CacheableDependencyInterface|mixed $object: The object whose cacheability metadata to retrieve. If it implements CacheableDependencyInterface, its cacheability metadata will be used, otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.
static
public static function createFromObject($object) { if ($object instanceof CacheableDependencyInterface) { $meta = new static(); $meta->cacheContexts = $object->getCacheContexts(); $meta->cacheTags = $object->getCacheTags(); $meta->cacheMaxAge = $object->getCacheMaxAge(); return $meta; } // Objects that don't implement CacheableDependencyInterface must be assumed // to be uncacheable, so set max-age 0. $meta = new static(); $meta->cacheMaxAge = 0; return $meta; }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Cache!CacheableMetadata.php/function/CacheableMetadata::createFromObject/8.1.x