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

[Cache] ProxyAdapter & TagAwareAdapter don't work together #30400

Closed
dmaicher opened this issue Feb 27, 2019 · 1 comment
Closed

[Cache] ProxyAdapter & TagAwareAdapter don't work together #30400

dmaicher opened this issue Feb 27, 2019 · 1 comment

Comments

@dmaicher
Copy link
Contributor

Symfony version(s) affected: 3.4 until master

Description
When wrapping an adapter inside a ProxyAdapter its impossible to use it within a TagAwareAdapter.

How to reproduce

$cache = new \Symfony\Component\Cache\Adapter\TagAwareAdapter(
    new \Symfony\Component\Cache\Adapter\ProxyAdapter(
        new \Symfony\Component\Cache\Adapter\ArrayAdapter()
    )
);

$item = $cache->getItem('foo');
$item->tag(['tag1', 'tag2']);
$item->set(true);
$cache->save($item);

var_dump($cache->getItem('foo')->get());

==>

array(2) {
  ["tag1"]=>
  int(0)
  ["tag2"]=>
  int(0)
}

So the actual value of the cache item is replaced by its tags.

@nicolas-grekas I tried to have a look and it seems to be related with the mysterious $innerItem of a CacheItem. If you could shed some light on this $innerItem and why it exists I might understand the logic and can fix it somehow 😊

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Cache/Adapter/TagAwareAdapter.php#L54

@flaushi
Copy link

flaushi commented Mar 19, 2019

Wow, I tried your code and you're right. Leaving the ProxyAdapter out resolves the problem.
It also does not help to supply a second Adapter for the tags pool

nicolas-grekas added a commit that referenced this issue Apr 7, 2019
…icher)

This PR was merged into the 3.4 branch.

Discussion
----------

[Cache] fix using ProxyAdapter inside TagAwareAdapter

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30400
| License       | MIT
| Doc PR        | -

EUFOSSA

After some debugging this is my first attempt to fix this issue @nicolas-grekas 😊 Let's discuss it.

without the fix the test fails like this:

```
Testing Symfony\Component\Cache\Tests\Adapter\TagAwareAndProxyAdapterIntegrationTest
F                                                                   1 / 1 (100%)

Time: 28 ms, Memory: 4.00MB

There was 1 failure:

1) Symfony\Component\Cache\Tests\Adapter\TagAwareAndProxyAdapterIntegrationTest::testIntegration
Failed asserting that Array &0 (
    'tag1' => 0
    'tag2' => 0
) is identical to 'bar'.

/var/www/symfony/src/Symfony/Component/Cache/Tests/Adapter/TagAwareAndProxyAdapterIntegrationTest.php:26

FAILURES!
Tests: 1, Assertions: 1, Failures: 1.

Commits
-------

98b9be9 [Cache] fix using ProxyAdapter inside TagAwareAdapter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants