Skip to content

Commit

Permalink
Remove support for Doctrine Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Apr 29, 2021
1 parent d01363e commit ddf3588
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 185 deletions.
11 changes: 11 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,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.3

## Deprecation of Doctrine Cache
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",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0",
"psr/cache": "^1|^2|^3"
Expand Down
6 changes: 0 additions & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +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
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 @@ -45,11 +45,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 @@ -66,15 +61,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 @@ -86,7 +72,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
67 changes: 4 additions & 63 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,53 +28,18 @@ class QueryCacheProfile
/** @var string|null */
private $cacheKey;

public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?object $resultCache = null)
public function __construct(int $lifetime = 0, ?string $cacheKey = null, ?CacheItemPoolInterface $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)
));
}
$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 @@ -130,23 +88,6 @@ public function setResultCache(CacheItemPoolInterface $cache): QueryCacheProfile
return new QueryCacheProfile($this->lifetime, $this->cacheKey, $cache);
}

/**
* @deprecated Use {@see setResultCache()} instead.
*
* @return QueryCacheProfile
*/
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
50 changes: 0 additions & 50 deletions tests/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\DBAL\Tests\Functional;

use Doctrine\Common\Cache\ArrayCache;
use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\Logging\DebugStack;
use Doctrine\DBAL\Result;
Expand Down Expand Up @@ -226,25 +225,6 @@ public function testFetchingAllRowsSavesCache(callable $fetchAll): void
self::assertCount(1, $layerCache->getItem('testcachekey')->get());
}

/**
* @dataProvider fetchAllProvider
*/
public function testFetchingAllRowsSavesCacheLegacy(callable $fetchAll): void
{
$layerCache = new ArrayCache();

$result = $this->connection->executeQuery(
'SELECT * FROM caching WHERE test_int > 500',
[],
[],
new QueryCacheProfile(0, 'testcachekey', $layerCache)
);

$fetchAll($result);

self::assertCount(1, $layerCache->fetch('testcachekey'));
}

/**
* @return iterable<string,list<mixed>>
*/
Expand Down Expand Up @@ -370,36 +350,6 @@ public function testChangeCacheImpl(): void
self::assertCount(1, $secondCache->getItem('emptycachekey')->get());
}

public function testChangeCacheImplLegacy(): void
{
$stmt = $this->connection->executeQuery(
'SELECT * FROM caching WHERE test_int > 500',
[],
[],
new QueryCacheProfile(10, 'emptycachekey')
);

$this->hydrateViaIteration($stmt, static function (Result $result) {
return $result->fetchAssociative();
});

$secondCache = new ArrayCache();

$stmt = $this->connection->executeQuery(
'SELECT * FROM caching WHERE test_int > 500',
[],
[],
new QueryCacheProfile(10, 'emptycachekey', $secondCache)
);

$this->hydrateViaIteration($stmt, static function (Result $result) {
return $result->fetchAssociative();
});

self::assertCount(2, $this->sqlLogger->queries, 'two hits');
self::assertCount(1, $secondCache->fetch('emptycachekey'));
}

/**
* @return iterable<string,array<int,mixed>>
*/
Expand Down

0 comments on commit ddf3588

Please sign in to comment.