-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[10.x] Fix Postgres cache store failed to put exist cache in transact…
…ion (#48968) * [10.x] Fix Postgres cache store failed to put exist cache in transaction * Test PostgresCacheStore integration test * [10.x] Improve put operation of database cache store - Prevent non-rollback error query occur in transaction - For existing keys they will have to execute two queries instead of just one with upserts * Add database cache store integration test * Chore: ad db cache store integration test to databases workflows * Fix SqlServerCacheStoreTest * Refactor db cache store integration test * Refactor db cache store integration test * Refactor style * wip --------- Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
- Loading branch information
Showing
3 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Database; | ||
|
||
use Illuminate\Support\Facades\Cache; | ||
use Illuminate\Support\Facades\DB; | ||
use Orchestra\Testbench\Attributes\WithMigration; | ||
|
||
#[WithMigration('cache')] | ||
class DatabaseCacheStoreTest extends DatabaseTestCase | ||
{ | ||
public function testValueCanStoreNewCache() | ||
{ | ||
$store = $this->getStore(); | ||
|
||
$store->put('foo', 'bar', 60); | ||
|
||
$this->assertSame('bar', $store->get('foo')); | ||
} | ||
|
||
public function testValueCanUpdateExistCache() | ||
{ | ||
$store = $this->getStore(); | ||
|
||
$store->put('foo', 'bar', 60); | ||
$store->put('foo', 'new-bar', 60); | ||
|
||
$this->assertSame('new-bar', $store->get('foo')); | ||
} | ||
|
||
public function testValueCanUpdateExistCacheInTransaction() | ||
{ | ||
$store = $this->getStore(); | ||
|
||
$store->put('foo', 'bar', 60); | ||
|
||
DB::beginTransaction(); | ||
$store->put('foo', 'new-bar', 60); | ||
DB::commit(); | ||
|
||
$this->assertSame('new-bar', $store->get('foo')); | ||
} | ||
|
||
protected function getStore() | ||
{ | ||
return Cache::store('database'); | ||
} | ||
} |