Project

General

Profile

Actions

Feature #89054

closed

Provide cache frontends via dependency injection

Added by Markus Poerschke about 5 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Should have
Category:
Caching
Start date:
2019-09-01
Due date:
% Done:

100%

Estimated time:
PHP Version:
Tags:
Complexity:
easy
Sprint Focus:

Description

Instead of injecting the CacheManager, a cache frontend should be injectable directly to a class.

TYPO3 v9 and before:

class MyClass
{
    /**
     * @var TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
     */
    private $cache;

    public function __construct()
    {
        $cacheManager = GeneralUtility::makeInstance(CacheManager::class);
        $this->cache = $cacheManager->getCache('my_cache');
    }
}

This code should become:

class MyClass
{
    /**
     * @var TYPO3\CMS\Core\Cache\Frontend\FrontendInterface
     */
    private $cache;

    public function __construct(FrontendInterface $cache)
    {
        $this->cache = $cache;
    }
}

Since the cache frontends are not added to the service container, the injection has to be configured manually or the CacheManager has to be inejcted.

This feature suggest to add a service for each cache configuration and name it "cache.[NAME OF CONFIGURATION]" to make it available within the service container.

This will allow to configure the service above as follows:

MyClass:
   arguments:
      $cache: '@cache.my_cache'
Actions

Also available in: Atom PDF