Skip to content

[Cache] Add PdoTagAwareAdapter #58296

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

Open
wants to merge 18 commits into
base: 7.4
Choose a base branch
from
Prev Previous commit
Next Next commit
Cleanup
  • Loading branch information
Toflar committed Nov 25, 2024
commit b67a05ade69191c2379e94b2da8a096ae016686e
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class AbstractTagAwareAdapter implements TagAwareAdapterInterface, TagA
use AbstractAdapterTrait;
use ContractsTrait;

private const TAGS_PREFIX = "\1tags\1";
protected const TAGS_PREFIX = "\1tags\1";

protected function __construct(string $namespace = '', int $defaultLifetime = 0)
{
Expand Down Expand Up @@ -168,7 +168,7 @@ protected function doDeleteYieldTags(array $ids): iterable
public function commit(): bool
{
$ok = true;
$byLifetime = (self::$mergeByLifetime)($this->deferred, $expiredIds, $this->getId(...), self::TAGS_PREFIX, $this->defaultLifetime);
$byLifetime = (self::$mergeByLifetime)($this->deferred, $expiredIds, $this->getId(...), static::TAGS_PREFIX, $this->defaultLifetime);
$retry = $this->deferred = [];

if ($expiredIds) {
Expand Down Expand Up @@ -244,7 +244,7 @@ public function deleteItems(array $keys): bool
try {
foreach ($this->doDeleteYieldTags(array_values($ids)) as $id => $tags) {
foreach ($tags as $tag) {
$tagData[$this->getId(self::TAGS_PREFIX.$tag)][] = $id;
$tagData[$this->getId(static::TAGS_PREFIX.$tag)][] = $id;
}
}
} catch (\Exception) {
Expand Down Expand Up @@ -283,7 +283,7 @@ public function invalidateTags(array $tags): bool

$tagIds = [];
foreach (array_unique($tags) as $tag) {
$tagIds[] = $this->getId(self::TAGS_PREFIX.$tag);
$tagIds[] = $this->getId(static::TAGS_PREFIX.$tag);
}

try {
Expand Down
8 changes: 8 additions & 0 deletions src/Symfony/Component/Cache/Adapter/PdoTagAwareAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,21 @@
use Symfony\Component\Cache\PruneableInterface;
use Symfony\Component\Cache\Traits\PdoTrait;

/**
* @author Yanick Witschi <yanick.witschi@terminal42.ch>
*/
class PdoTagAwareAdapter extends AbstractTagAwareAdapter implements PruneableInterface
{
use PdoTrait {
doSave as public doSaveItem;
prune as public pruneItems;
}

/**
* No need for a prefix here, should improve lookup time.
*/
protected const TAGS_PREFIX = '';

/**
* You can either pass an existing database connection as PDO instance or
* a DSN string that will be used to lazy-connect to the database when the
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Cache/Traits/PdoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ protected function doSave(array $values, int $lifetime): array|bool
$lifetime = $lifetime ?: null;

$stmt = $this->prepareStatementWithFallback($sql, function () {
$this->createTable();
$this->createItemsTable();
});

// $id and $data are defined later in the loop. Binding is done by reference, values are read on execution.
Expand Down Expand Up @@ -247,7 +247,7 @@ protected function doSave(array $values, int $lifetime): array|bool

foreach ($values as $id => $data) {
$this->executeStatementWithFallback($stmt, function () {
$this->createTable();
$this->createItemsTable();
});

if (null === $driver && !$stmt->rowCount()) {
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy