forked from TruCopilot/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMemcachedAlternativeConfigurationSyntax.test.php
More file actions
85 lines (69 loc) · 2.57 KB
/
MemcachedAlternativeConfigurationSyntax.test.php
File metadata and controls
85 lines (69 loc) · 2.57 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
*
* This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
*
* @author Georges.L (Geolim4) <contact@geolim4.com>
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
use Phpfastcache\CacheManager;
use Phpfastcache\Drivers\Memcached\Config as MemcachedConfig;
use Phpfastcache\Tests\Helper\TestHelper;
chdir(__DIR__);
require_once __DIR__ . '/../vendor/autoload.php';
$testHelper = new TestHelper('Memcached alternative configuration syntax');
$cacheInstanceDefSyntax = CacheManager::getInstance('Memcached');
$cacheInstanceOldSyntax = CacheManager::getInstance('Memcached', new MemcachedConfig([
'servers' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'saslUser' => null,
'saslPassword' => null,
]
]
]));
$cacheInstanceNewSyntax = CacheManager::getInstance('Memcached', new MemcachedConfig([
'host' => '127.0.0.1',
'port' => 11211,
]));
$cacheKey = 'cacheKey';
$RandomCacheValue = str_shuffle(uniqid('pfc', true));
$cacheItem = $cacheInstanceDefSyntax->getItem($cacheKey);
$cacheItem->set($RandomCacheValue)->expiresAfter(600);
$cacheInstanceDefSyntax->save($cacheItem);
unset($cacheItem);
$cacheInstanceDefSyntax->detachAllItems();
$cacheItem = $cacheInstanceOldSyntax->getItem($cacheKey);
$cacheItem->set($RandomCacheValue)->expiresAfter(600);
$cacheInstanceOldSyntax->save($cacheItem);
unset($cacheItem);
$cacheInstanceOldSyntax->detachAllItems();
$cacheItem = $cacheInstanceNewSyntax->getItem($cacheKey);
$cacheItem->set($RandomCacheValue)->expiresAfter(600);
$cacheInstanceNewSyntax->save($cacheItem);
unset($cacheItem);
$cacheInstanceNewSyntax->detachAllItems();
if ($cacheInstanceDefSyntax->getItem($cacheKey)->isHit()) {
$testHelper->assertPass('The default Memcached syntax is working well');
} else {
$testHelper->assertFail('The default Memcached syntax is not working');
}
if ($cacheInstanceOldSyntax->getItem($cacheKey)->isHit()) {
$testHelper->assertPass('The old Memcached syntax is working well');
} else {
$testHelper->assertFail('The old Memcached syntax is not working');
}
if ($cacheInstanceNewSyntax->getItem($cacheKey)->isHit()) {
$testHelper->assertPass('The new Memcached syntax is working well');
} else {
$testHelper->assertFail('The new Memcached syntax is not working');
}
$cacheInstanceDefSyntax->clear();
$cacheInstanceOldSyntax->clear();
$cacheInstanceNewSyntax->clear();
$testHelper->terminateTest();