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 #1

Updated by Gerrit Code Review about 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61588

Actions #2

Updated by Gerrit Code Review about 5 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61588

Actions #3

Updated by Markus Poerschke about 5 years ago

  • Assignee set to Markus Poerschke
  • % Done changed from 0 to 80

Changes in documentation can be found in this Pull Request on GitHub: https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-CoreApi/pull/574

Actions #4

Updated by Gerrit Code Review about 5 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61588

Actions #5

Updated by Gerrit Code Review about 5 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61588

Actions #6

Updated by Gerrit Code Review about 5 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/61588

Actions #7

Updated by Anonymous about 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 80 to 100
Actions #8

Updated by Benni Mack almost 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF