-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connection parameters are cached hashed
- Loading branch information
Showing
2 changed files
with
89 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,19 @@ | |
namespace Doctrine\DBAL\Cache; | ||
|
||
use Doctrine\Common\Cache\Cache; | ||
use function hash; | ||
use function serialize; | ||
use function sha1; | ||
|
||
/** | ||
* Query Cache Profile handles the data relevant for query caching. | ||
* | ||
* It is a value object, setter methods return NEW instances. | ||
* | ||
* @author Benjamin Eberlei <[email protected]> | ||
*/ | ||
class QueryCacheProfile | ||
{ | ||
/** | ||
* @var \Doctrine\Common\Cache\Cache|null | ||
* @var Cache|null | ||
*/ | ||
private $resultCacheDriver; | ||
|
||
|
@@ -46,19 +47,18 @@ class QueryCacheProfile | |
private $cacheKey; | ||
|
||
/** | ||
* @param int $lifetime | ||
* @param string|null $cacheKey | ||
* @param \Doctrine\Common\Cache\Cache|null $resultCache | ||
* @param int $lifetime | ||
* @param string|null $cacheKey | ||
*/ | ||
public function __construct($lifetime = 0, $cacheKey = null, Cache $resultCache = null) | ||
public function __construct($lifetime = 0, $cacheKey = null, ?Cache $resultCache = null) | ||
{ | ||
$this->lifetime = $lifetime; | ||
$this->cacheKey = $cacheKey; | ||
$this->lifetime = $lifetime; | ||
$this->cacheKey = $cacheKey; | ||
$this->resultCacheDriver = $resultCache; | ||
} | ||
|
||
/** | ||
* @return \Doctrine\Common\Cache\Cache|null | ||
* @return Cache|null | ||
*/ | ||
public function getResultCacheDriver() | ||
{ | ||
|
@@ -76,7 +76,7 @@ public function getLifetime() | |
/** | ||
* @return string | ||
* | ||
* @throws \Doctrine\DBAL\Cache\CacheException | ||
* @throws CacheException | ||
*/ | ||
public function getCacheKey() | ||
{ | ||
|
@@ -102,7 +102,7 @@ public function generateCacheKeys($query, $params, $types, array $connectionPara | |
$realCacheKey = 'query=' . $query . | ||
'¶ms=' . serialize($params) . | ||
'&types=' . serialize($types) . | ||
'&connectionParams=' . serialize($connectionParams); | ||
'&connectionParams=' . hash('sha256', serialize($connectionParams)); | ||
|
||
// should the key be automatically generated using the inputs or is the cache key set? | ||
if ($this->cacheKey === null) { | ||
|
@@ -111,11 +111,10 @@ public function generateCacheKeys($query, $params, $types, array $connectionPara | |
$cacheKey = $this->cacheKey; | ||
} | ||
|
||
return array($cacheKey, $realCacheKey); | ||
return [$cacheKey, $realCacheKey]; | ||
} | ||
|
||
/** | ||
* @param \Doctrine\Common\Cache\Cache $cache | ||
* | ||
* @return \Doctrine\DBAL\Cache\QueryCacheProfile | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters