1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
<?php
namespace Illuminate\Tests\Integration\Cache;
use Illuminate\Support\Facades\Cache;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
#[RequiresPhpExtension('memcached')]
class MemcachedTaggedCacheTestCase extends MemcachedIntegrationTestCase
{
public function testMemcachedCanStoreAndRetrieveTaggedCacheItems()
{
$store = Cache::store('memcached');
$store->tags(['people', 'artists'])->put('John', 'foo', 2);
$store->tags(['people', 'authors'])->put('Anne', 'bar', 2);
$this->assertSame('foo', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('bar', $store->tags(['people', 'authors'])->get('Anne'));
$store->tags(['people', 'artists'])->put('John', 'baz');
$store->tags(['people', 'authors'])->put('Anne', 'qux');
$this->assertSame('baz', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('qux', $store->tags(['people', 'authors'])->get('Anne'));
$store->tags('authors')->flush();
$this->assertNull($store->tags(['people', 'authors'])->get('Anne'));
$store->tags(['people', 'authors'])->flush();
$this->assertNull($store->tags(['people', 'artists'])->get('John'));
}
public function testMemcachedCanStoreManyTaggedCacheItems()
{
$store = Cache::store('memcached');
$store->tags(['people', 'artists'])->putMany(['John' => 'foo', 'Jane' => 'bar'], 2);
$this->assertSame('foo', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('bar', $store->tags(['people', 'artists'])->get('Jane'));
$store->tags(['people', 'artists'])->putMany(['John' => 'baz', 'Jane' => 'qux']);
$this->assertSame('baz', $store->tags(['people', 'artists'])->get('John'));
$this->assertSame('qux', $store->tags(['people', 'artists'])->get('Jane'));
$store->tags(['people', 'artists'])->putMany(['John' => 'baz', 'Jane' => 'qux'], -1);
$this->assertNull($store->tags(['people', 'artists'])->get('John'));
$this->assertNull($store->tags(['people', 'artists'])->get('Jane'));
}
}
|