Skip to content

Commit 331a457

Browse files
committed
verify the symfony cache works
1 parent da00ae0 commit 331a457

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

Spanner/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"google/cloud-pubsub": "^2.0",
2020
"dg/bypass-finals": "^1.7",
2121
"dms/phpunit-arraysubset-asserts": "^0.5.0",
22-
"symfony/process": "^6.4"
22+
"symfony/process": "^6.4",
23+
"symfony/cache": " ^6.4"
2324
},
2425
"suggest": {
2526
"ext-protobuf": "Provides a significant increase in throughput over the pure PHP protobuf implementation. See https://cloud.google.com/php/grpc for installation instructions.",

Spanner/src/Session/SessionCache.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ private function isExpired(): bool
188188
*/
189189
private function getDefaultLock(string $cacheKey): LockInterface
190190
{
191-
// if ($this->isSysvIPCLoaded()) {
192-
// return new SemaphoreLock(
193-
// $this->getSysvKey(crc32($cacheKey))
194-
// );
195-
// }
191+
if ($this->isSysvIPCLoaded()) {
192+
return new SemaphoreLock(
193+
$this->getSysvKey(crc32($cacheKey))
194+
);
195+
}
196196

197197
return new FlockLock($cacheKey);
198198
}

Spanner/tests/Unit/Session/SessionCacheTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Prophecy\PhpUnit\ProphecyTrait;
2828
use Psr\Cache\CacheItemInterface;
2929
use Psr\Cache\CacheItemPoolInterface;
30+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
3031
use Symfony\Component\Process\Process;
3132

3233
/**
@@ -179,7 +180,8 @@ public function testCacheLocking()
179180
$sessionCache = new SessionCache(
180181
$this->spannerClient->reveal(),
181182
$databaseName,
182-
['cacheItemPool' => new FileSystemCacheItemPool($cachePath)],
183+
// ['cacheItemPool' => new FileSystemCacheItemPool($cachePath)],
184+
['cacheItemPool' => new FilesystemAdapter($databaseId)]
183185
);
184186

185187
$process = new Process(['php', __DIR__ . '/lock_test_process.php', $databaseName, $cachePath]);

Spanner/tests/Unit/Session/lock_test_process.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Google\Cloud\Spanner\V1\Client\SpannerClient;
1010
use Prophecy\Argument;
1111
use Prophecy\PhpUnit\ProphecyTrait;
12+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1213

1314
/**
1415
* Runs a process which is designed to wait while a session is acquired.
@@ -59,10 +60,12 @@ public function run(): string
5960
->will(function () {
6061
throw new \Exception('createSession called in child process - this shouldn\'t happen');
6162
});
63+
$parts = explode('/', $this->databaseName);
6264
$sessionCache = new SessionCache(
6365
$spannerClient->reveal(),
6466
$this->databaseName,
65-
['cacheItemPool' => new FileSystemCacheItemPool($this->cachePath)]
67+
// ['cacheItemPool' => new FileSystemCacheItemPool($this->cachePath)]
68+
['cacheItemPool' => new FilesystemAdapter(array_pop($parts))]
6669
);
6770
// 2. FORCIBLY UNREGISTER the bypass stream wrapper (file)
6871
if (stream_wrapper_unregister('file')) {

0 commit comments

Comments
 (0)