Drupal cache dependency injection
As with many things in Drupal 8... the switch from Drupal 7 changed so many things, that nearly all of the previous decades worth of documentation build up became lost. That means a lot of the simple useful explanations for basic questions are not present, and more often than not a search will instead yield some obtuse philosophical explanation for something.
When it comes to bringing cache in via Dependency injection, there just wasn't a solid example out there at all. So, here's the first for you all!
use Drupal\Core\Cache\CacheBackendInterface;
/**
* constructor.
*/
public function __construct(CacheBackendInterface $staticCache) {
$this->cache = $staticCache;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('cache.default'),
);
}