Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

!!! FEATURE: Extract LowLevelFrontendInterface and implement PSR-6 and PSR-16 as cache frontends to be used via Caches.yaml #3239

Open
wants to merge 1 commit into
base: 9.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions Neos.Cache/Classes/Backend/AbstractBackend.php
Expand Up @@ -14,7 +14,7 @@
*/

use Neos\Cache\EnvironmentConfiguration;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* An abstract caching backend
Expand All @@ -28,7 +28,7 @@ abstract class AbstractBackend implements BackendInterface

/**
* Reference to the cache frontend which uses this backend
* @var FrontendInterface
* @var LowLevelFrontendInterface
*/
protected $cache;

Expand Down Expand Up @@ -109,11 +109,11 @@ protected function setProperty(string $propertyName, $propertyValue): bool
/**
* Sets a reference to the cache frontend which uses this backend
*
* @param FrontendInterface $cache The frontend for this backend
* @param LowLevelFrontendInterface $cache The frontend for this backend
* @return void
* @api
*/
public function setCache(FrontendInterface $cache): void
public function setCache(LowLevelFrontendInterface $cache): void
{
$this->cache = $cache;
$this->cacheIdentifier = $this->cache->getIdentifier();
Expand Down
10 changes: 5 additions & 5 deletions Neos.Cache/Classes/Backend/ApcuBackend.php
Expand Up @@ -16,7 +16,7 @@
use Neos\Cache\Backend\AbstractBackend as IndependentAbstractBackend;
use Neos\Cache\EnvironmentConfiguration;
use Neos\Cache\Exception;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* A caching backend which stores cache entries by using APCu.
Expand Down Expand Up @@ -76,10 +76,10 @@ public function __construct(EnvironmentConfiguration $environmentConfiguration,
/**
* Initializes the identifier prefix when setting the cache.
*
* @param FrontendInterface $cache
* @param LowLevelFrontendInterface $cache
* @return void
*/
public function setCache(FrontendInterface $cache): void
public function setCache(LowLevelFrontendInterface $cache): void
{
parent::setCache($cache);

Expand Down Expand Up @@ -119,7 +119,7 @@ public function getPrefixedIdentifier(string $entryIdentifier): string
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
{
if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1232986818);
}

Expand Down Expand Up @@ -222,7 +222,7 @@ protected function findTagsByIdentifier(string $identifier): array
*/
public function flush(): void
{
if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('Yet no cache frontend has been set via setCache().', 1232986971);
}
$this->flushByTag('%APCUBE%' . $this->cacheIdentifier);
Expand Down
6 changes: 3 additions & 3 deletions Neos.Cache/Classes/Backend/BackendInterface.php
Expand Up @@ -13,7 +13,7 @@
* source code.
*/

use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* A contract for a Cache Backend
Expand All @@ -25,11 +25,11 @@ interface BackendInterface
/**
* Sets a reference to the cache frontend which uses this backend
*
* @param FrontendInterface $cache The frontend for this backend
* @param LowLevelFrontendInterface $cache The frontend for this backend
* @return void
* @api
*/
public function setCache(FrontendInterface $cache): void;
public function setCache(LowLevelFrontendInterface $cache): void;

/**
* Returns the internally used, prefixed entry identifier for the given public
Expand Down
6 changes: 3 additions & 3 deletions Neos.Cache/Classes/Backend/FileBackend.php
Expand Up @@ -14,7 +14,7 @@
*/

use Neos\Cache\Exception;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;
use Neos\Utility\Exception\FilesException;
use Neos\Utility\Files;
use Neos\Utility\OpcodeCacheHelper;
Expand Down Expand Up @@ -115,11 +115,11 @@ public function isFrozen(): bool
* This method also detects if this backend is frozen and sets the internal
* flag accordingly.
*
* @param FrontendInterface $cache The cache frontend
* @param LowLevelFrontendInterface $cache The cache frontend
* @return void
* @throws Exception
*/
public function setCache(FrontendInterface $cache): void
public function setCache(LowLevelFrontendInterface $cache): void
{
parent::setCache($cache);

Expand Down
10 changes: 5 additions & 5 deletions Neos.Cache/Classes/Backend/MemcachedBackend.php
Expand Up @@ -16,7 +16,7 @@
use Neos\Cache\Backend\AbstractBackend as IndependentAbstractBackend;
use Neos\Cache\EnvironmentConfiguration;
use Neos\Cache\Exception;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* A caching backend which stores cache entries by using Memcache/Memcached.
Expand Down Expand Up @@ -158,10 +158,10 @@ protected function setCompression(bool $useCompression)
/**
* Initializes the identifier prefix when setting the cache.
*
* @param FrontendInterface $cache
* @param LowLevelFrontendInterface $cache
* @return void
*/
public function setCache(FrontendInterface $cache): void
public function setCache(LowLevelFrontendInterface $cache): void
{
parent::setCache($cache);

Expand Down Expand Up @@ -204,7 +204,7 @@ public function set(string $entryIdentifier, string $data, array $tags = [], int
if (strlen($this->getPrefixedIdentifier($entryIdentifier)) > 250) {
throw new \InvalidArgumentException('Could not set value. Key more than 250 characters (' . $this->getPrefixedIdentifier($entryIdentifier) . ').', 1232969508);
}
if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1207149215);
}

Expand Down Expand Up @@ -342,7 +342,7 @@ protected function findTagsByIdentifier(string $identifier): array
*/
public function flush(): void
{
if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('Yet no cache frontend has been set via setCache().', 1204111376);
}

Expand Down
4 changes: 2 additions & 2 deletions Neos.Cache/Classes/Backend/PdoBackend.php
Expand Up @@ -15,7 +15,7 @@

use Neos\Cache\Backend\AbstractBackend as IndependentAbstractBackend;
use Neos\Cache\Exception;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;
use Neos\Error\Messages\Error;
use Neos\Error\Messages\Notice;
use Neos\Error\Messages\Result;
Expand Down Expand Up @@ -186,7 +186,7 @@ public function set(string $entryIdentifier, string $data, array $tags = [], int
{
$this->connect();

if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1259515600);
}

Expand Down
6 changes: 3 additions & 3 deletions Neos.Cache/Classes/Backend/SimpleFileBackend.php
Expand Up @@ -21,7 +21,7 @@
use Neos\Utility\Files;
use Neos\Cache\Exception;
use Neos\Cache\Frontend\PhpFrontend;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;
use Neos\Utility\Exception\FilesException;
use Neos\Utility\OpcodeCacheHelper;

Expand Down Expand Up @@ -99,11 +99,11 @@ public function __construct(EnvironmentConfiguration $environmentConfiguration,
* Sets a reference to the cache frontend which uses this backend and
* initializes the default cache directory.
*
* @param FrontendInterface $cache The cache frontend
* @param LowLevelFrontendInterface $cache The cache frontend
* @return void
* @throws Exception
*/
public function setCache(FrontendInterface $cache): void
public function setCache(LowLevelFrontendInterface $cache): void
{
parent::setCache($cache);
$this->cacheEntryFileExtension = ($cache instanceof PhpFrontend) ? '.php' : '';
Expand Down
4 changes: 2 additions & 2 deletions Neos.Cache/Classes/Backend/TransientMemoryBackend.php
Expand Up @@ -15,7 +15,7 @@

use Neos\Cache\Backend\AbstractBackend as IndependentAbstractBackend;
use Neos\Cache\Exception;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* A caching backend which stores cache entries during one script run.
Expand Down Expand Up @@ -47,7 +47,7 @@ class TransientMemoryBackend extends IndependentAbstractBackend implements Tagga
*/
public function set(string $entryIdentifier, string $data, array $tags = [], int $lifetime = null): void
{
if (!$this->cache instanceof FrontendInterface) {
if (!$this->cache instanceof LowLevelFrontendInterface) {
throw new Exception('No cache frontend has been set yet via setCache().', 1238244992);
}

Expand Down
12 changes: 6 additions & 6 deletions Neos.Cache/Classes/CacheFactory.php
Expand Up @@ -14,7 +14,7 @@
use Neos\Cache\Backend\BackendInterface;
use Neos\Cache\Exception\InvalidBackendException;
use Neos\Cache\Exception\InvalidCacheException;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* This cache factory takes care of instantiating a cache frontend and injecting
Expand Down Expand Up @@ -50,12 +50,12 @@ public function __construct(EnvironmentConfiguration $environmentConfiguration)
* @param string $cacheObjectName Object name of the cache frontend
* @param string $backendObjectName Object name of the cache backend
* @param array $backendOptions (optional) Array of backend options
* @return FrontendInterface The created cache frontend
* @return LowLevelFrontendInterface The created cache frontend
* @throws InvalidBackendException
* @throws InvalidCacheException
* @api
*/
public function create(string $cacheIdentifier, string $cacheObjectName, string $backendObjectName, array $backendOptions = []): FrontendInterface
public function create(string $cacheIdentifier, string $cacheObjectName, string $backendObjectName, array $backendOptions = []): LowLevelFrontendInterface
{
$backend = $this->instantiateBackend($backendObjectName, $backendOptions, $this->environmentConfiguration);
$cache = $this->instantiateCache($cacheIdentifier, $cacheObjectName, $backend);
Expand All @@ -68,13 +68,13 @@ public function create(string $cacheIdentifier, string $cacheObjectName, string
* @param string $cacheIdentifier
* @param string $cacheObjectName
* @param BackendInterface $backend
* @return FrontendInterface
* @return LowLevelFrontendInterface
* @throws InvalidCacheException
*/
protected function instantiateCache(string $cacheIdentifier, string $cacheObjectName, BackendInterface $backend): FrontendInterface
protected function instantiateCache(string $cacheIdentifier, string $cacheObjectName, BackendInterface $backend): LowLevelFrontendInterface
{
$cache = new $cacheObjectName($cacheIdentifier, $backend);
if (!$cache instanceof FrontendInterface) {
if (!$cache instanceof LowLevelFrontendInterface) {
throw new InvalidCacheException('"' . $cacheObjectName . '" is not a valid cache frontend object.', 1216304300);
}

Expand Down
6 changes: 3 additions & 3 deletions Neos.Cache/Classes/CacheFactoryInterface.php
Expand Up @@ -12,7 +12,7 @@
*/
use Neos\Cache\Exception\InvalidCacheException;
use Neos\Cache\Exception\InvalidBackendException;
use Neos\Cache\Frontend\FrontendInterface;
use Neos\Cache\Frontend\LowLevelFrontendInterface;

/**
* This cache factory takes care of instantiating a cache frontend and injecting
Expand All @@ -31,10 +31,10 @@ interface CacheFactoryInterface
* @param string $cacheObjectName Object name of the cache frontend
* @param string $backendObjectName Object name of the cache backend
* @param array $backendOptions (optional) Array of backend options
* @return \Neos\Cache\Frontend\FrontendInterface The created cache frontend
* @return \Neos\Cache\Frontend\LowLevelFrontendInterface The created cache frontend
* @throws InvalidBackendException
* @throws InvalidCacheException
* @api
*/
public function create(string $cacheIdentifier, string $cacheObjectName, string $backendObjectName, array $backendOptions = []): FrontendInterface;
public function create(string $cacheIdentifier, string $cacheObjectName, string $backendObjectName, array $backendOptions = []): LowLevelFrontendInterface;
}