googleapis/google-cloud-php

[Spanner] CacheSessionPool::clear deletes the entire cache

taka-oyama opened this issue · 4 comments

It shouldn't be doing that.
It should only delete the key(s) that are relevant.

Environment details

Irrelevant.

Steps to reproduce

  1. Set unrelated item to the CacheItemPool
  2. create new CacheSessionPool using CacheItemPool
  3. Call CacheSessionPool::clear()

Code example

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

// set an unrelated item
$item = $cache->getItem('dummy')->set('hi');
$cache->save($item);

$connection = (new SpannerClient())->connect(
    getenv('SPANNER_INSTANCE'),
    getenv('SPANNER_DATABASE'),
    ['sessionPool' => new CacheSessionPool($cache)],
);

var_dump($cache->hasItem('dummy')); // true

$connection->sessionPool()?->clear();

var_dump($cache->hasItem('dummy')); // false

See the code below.

$this->cacheItemPool->clear();

This should probably be $this->cacheItemPool->deleteItem($item);.