Skip to content

[Cache] Incompatibility between ChainCache and ChainAdapter #37263

Closed
@philipp-kolesnikov

Description

@philipp-kolesnikov

Symfony version(s) affected: 4.4+

Description
Default lifetime handling in underlying caches of chain cache differs in ChainCache and ChainAdapter. It's not clear for me if this is bug or intended change.

How to reproduce
Let assume that we have several caches with default lifetime is set and these caches are chained and chain cache has no default lifetime.

In case of ChainCache, when some value is saved its lifetime in underlying cache is set to corresponding cache default lifetime.

$cache1 = new ArrayCache(0);
$cache2 = new ArrayCache(2);

$chainCache = new ChainCache([$cache1, $cache2]);

$chainCache->set("key", "test");

Lifetime of "key" in $cache1 will be 0, and lifetime in $cache2 will be 2.

In case of ChainAdapter, lifetime of item in all underlying caches will be set to lifetime of first item found.

$adapter1 = new ArrayAdapter(0);
$cache1 = new Psr16Cache($adapter1);

$adapter2 = new ArrayAdapter(2);
$cache2 = new Psr16Cache($adapter2);

$chainCache = new Psr16Cache(new ChainAdapter([$adapter1, $adapter2]));

$chainCache->set("key", "test");

Lifetime of "key" in all caches will be 2.

$adapter1 = new ArrayAdapter(0);
$cache1 = new Psr16Cache($adapter1);

$adapter2 = new ArrayAdapter(2);
$cache2 = new Psr16Cache($adapter2);

$cache1->set("key", "test1");

$chainCache = new Psr16Cache(new ChainAdapter([$adapter1, $adapter2]));

$chainCache->set("key", "test");

Lifetime of "key" in all caches will be 0 because it was set in $cache1 earlier.

Here (https://github.com/philipp-kolesnikov/cachetest) is sample test. I'd expect that all test cases shall be passed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions