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

Remove support for Doctrine Cache #4626

Merged
merged 1 commit into from
Jun 7, 2021
Merged
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
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ The Doctrine\DBAL\Version class is no longer available: please refrain from chec
Use binary fields of a size which fits all target platforms, or use blob explicitly instead.
- Binary fields are no longer represented as streams in PHP. They are represented as strings.

## BC BREAK: Removal of Doctrine Cache

The following methods have been removed.

| class | method | replacement |
| ------------------- | ------------------------ | ------------------ |
| `Configuration` | `setResultCacheImpl()` | `setResultCache()` |
| `Configuration` | `getResultCacheImpl()` | `getResultCache()` |
| `QueryCacheProfile` | `setResultCacheDriver()` | `setResultCache()` |
| `QueryCacheProfile` | `getResultCacheDriver()` | `getResultCache()` |

# Upgrade to 3.2

## Introduction of PSR-6 for result caching
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"require": {
"php": "^7.3 || ^8.0",
"composer/package-versions-deprecated": "^1.11.99",
"doctrine/cache": "^1.11|^2.0",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0",
"psr/cache": "^1|^2|^3"
Expand Down
12 changes: 0 additions & 12 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,6 @@ parameters:
message: '~^Instanceof between Doctrine\\DBAL\\Platforms\\Keywords\\KeywordList and Doctrine\\DBAL\\Platforms\\Keywords\\KeywordList will always evaluate to true\.~'
paths:
- %currentWorkingDirectory%/src/Platforms/AbstractPlatform.php

# We're checking for invalid invalid input
-
message: "#^Strict comparison using \\!\\=\\= between null and null will always evaluate to false\\.$#"
count: 1
path: src/Cache/QueryCacheProfile.php

# The Doctrine\Common\Cache\ArrayCache class won't exist if doctrine/cache 2 is installed
# TODO: remove by 4.0.0
-
message: '~^Parameter #3 \$resultCache of class Doctrine\\DBAL\\Cache\\QueryCacheProfile constructor expects Doctrine\\Common\\Cache\\Cache\|Psr\\Cache\\CacheItemPoolInterface\|null, Doctrine\\Common\\Cache\\ArrayCache given\.~'
path: tests/Functional/ResultCacheTest.php
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
15 changes: 0 additions & 15 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
is no longer supported.
-->
<file name="src/Tools/Console/ConsoleRunner.php"/>
<!--
This suppression should be removed once Doctrine Cache
is no longer supported.
-->
<file name="tests/Functional/ResultCacheTest.php"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
Expand All @@ -67,15 +62,6 @@
<referencedMethod name="Doctrine\DBAL\Statement::execute"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
This suppression should be removed in 4.0.x
See https://github.com/doctrine/dbal/pull/4620
-->
<file name="src/Configuration.php"/>
</errorLevel>
</DeprecatedProperty>
<DocblockTypeContradiction>
<errorLevel type="suppress">
<!--
Expand All @@ -87,7 +73,6 @@
1. Union types not supported at the language level (require dropping PHP 7 support)
2. Associative arrays with typed elements used instead of classes (require breaking API changes)
-->
<file name="src/Cache/QueryCacheProfile.php"/>
<file name="src/Connection.php"/>
<file name="src/Driver/IBMDB2/Statement.php"/>
<file name="src/DriverManager.php"/>
Expand Down
73 changes: 8 additions & 65 deletions src/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@

namespace Doctrine\DBAL\Cache;

use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\DBAL\Cache\Exception\NoCacheKey;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use Psr\Cache\CacheItemPoolInterface;
use TypeError;

use function get_class;
use function hash;
use function serialize;
use function sha1;
use function sprintf;

/**
* Query Cache Profile handles the data relevant for query caching.
Expand All @@ -35,56 +28,21 @@ class QueryCacheProfile
/** @var string|null */
private $cacheKey;

/**
* @param CacheItemPoolInterface|Cache|null $resultCache
*/
public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?object $resultCache = null)
{
$this->lifetime = $lifetime;
$this->cacheKey = $cacheKey;
if ($resultCache instanceof CacheItemPoolInterface) {
$this->resultCache = $resultCache;
} elseif ($resultCache instanceof Cache) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4620',
'Passing an instance of %s to %s as $resultCache is deprecated. Pass an instance of %s instead.',
Cache::class,
__METHOD__,
CacheItemPoolInterface::class
);

$this->resultCache = CacheAdapter::wrap($resultCache);
} elseif ($resultCache !== null) {
throw new TypeError(sprintf(
'$resultCache: Expected either null or an instance of %s or %s, got %s.',
CacheItemPoolInterface::class,
Cache::class,
get_class($resultCache)
));
}
public function __construct(
int $lifetime = 0,
?string $cacheKey = null,
?CacheItemPoolInterface $resultCache = null
) {
$this->lifetime = $lifetime;
$this->cacheKey = $cacheKey;
$this->resultCache = $resultCache;
}

public function getResultCache(): ?CacheItemPoolInterface
{
return $this->resultCache;
}

/**
* @deprecated Use {@see getResultCache()} instead.
*/
public function getResultCacheDriver(): ?Cache
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4620',
'%s is deprecated, call getResultCache() instead.',
__METHOD__
);

return $this->resultCache !== null ? DoctrineProvider::wrap($this->resultCache) : null;
}

public function getLifetime(): int
{
return $this->lifetime;
Expand Down Expand Up @@ -133,21 +91,6 @@ public function setResultCache(CacheItemPoolInterface $cache): QueryCacheProfile
return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache);
}

/**
* @deprecated Use {@see setResultCache()} instead.
*/
public function setResultCacheDriver(Cache $cache): self
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4620',
'%s is deprecated, call setResultCache() instead.',
__METHOD__
);

return new QueryCacheProfile($this->lifetime, $this->cacheKey, CacheAdapter::wrap($cache));
}

public function setCacheKey(?string $cacheKey): self
{
return new QueryCacheProfile($this->lifetime, $cacheKey, $this->resultCache);
Expand Down
51 changes: 1 addition & 50 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

namespace Doctrine\DBAL;

use Doctrine\Common\Cache\Cache;
use Doctrine\Common\Cache\Psr6\CacheAdapter;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\DBAL\Driver\Middleware;
use Doctrine\DBAL\Logging\NullLogger;
use Doctrine\DBAL\Logging\SQLLogger;
use Doctrine\Deprecations\Deprecation;
use Psr\Cache\CacheItemPoolInterface;

/**
Expand All @@ -35,15 +31,6 @@ class Configuration
*/
private $resultCache;

/**
* The cache driver implementation that is used for query result caching.
*
* @deprecated Use {@see $resultCache} instead.
*
* @var Cache|null
*/
protected $resultCacheImpl;

/**
* The callable to use to filter schema assets.
*
Expand Down Expand Up @@ -82,48 +69,12 @@ public function getResultCache(): ?CacheItemPoolInterface
return $this->resultCache;
}

/**
* Gets the cache driver implementation that is used for query result caching.
*
* @deprecated Use {@see getResultCache()} instead.
*/
public function getResultCacheImpl(): ?Cache
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4620',
'%s is deprecated, call getResultCache() instead.',
__METHOD__
);

return $this->resultCacheImpl;
}

/**
* Sets the cache driver implementation that is used for query result caching.
*/
public function setResultCache(CacheItemPoolInterface $cache): void
{
$this->resultCacheImpl = DoctrineProvider::wrap($cache);
$this->resultCache = $cache;
}

/**
* Sets the cache driver implementation that is used for query result caching.
*
* @deprecated Use {@see setResultCache()} instead.
*/
public function setResultCacheImpl(Cache $cacheImpl): void
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4620',
'%s is deprecated, call setResultCache() instead.',
__METHOD__
);

$this->resultCacheImpl = $cacheImpl;
$this->resultCache = CacheAdapter::wrap($cacheImpl);
$this->resultCache = $cache;
}

/**
Expand Down