forked from PHPSocialNetwork/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetchAllKeys.php
More file actions
56 lines (47 loc) · 1.29 KB
/
fetchAllKeys.php
File metadata and controls
56 lines (47 loc) · 1.29 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
<?php
/**
*
* This file is part of phpFastCache.
*
* @license MIT License (MIT)
*
* For full copyright and license information, please see the docs/CREDITS.txt file.
*
* @author Khoa Bui (khoaofgod) <khoaofgod@gmail.com> https://www.phpfastcache.com
* @author Georges.L (Geolim4) <contact@geolim4.com>
*
*/
use Phpfastcache\CacheManager;
// Include composer autoloader
require __DIR__ . '/../../vendor/autoload.php';
$InstanceCache = CacheManager::getInstance('files');
$InstanceCache->clear();
/**
* @var $keys \Phpfastcache\Core\Item\ExtendedCacheItemInterface[]
*/
$keyPrefix = "product_page_";
$keys = [];
for ($i=1;$i<=10;$i++)
{
$keys[$keyPrefix . $i] = $InstanceCache->getItem($keyPrefix . $i);
if(!$keys[$keyPrefix . $i]->isHit()){
$keys[$keyPrefix . $i]
->set(uniqid('pfc', true))
->addTag('pfc');
}
}
$InstanceCache->saveMultiple($keys);
/**
* Remove items references from memory
*/
unset($keys);
$InstanceCache->detachAllItems();
gc_collect_cycles();
/**
* Now get the items by a specific tag
*/
$keys = $InstanceCache->getItemsByTag('pfc');
foreach ($keys as $key) {
echo "Key: {$key->getKey()} => {$key->get()}<br />";
}
echo '<br /><br /><a href="/">Back to index</a> -- <a href="./' . basename(__FILE__) . '">Reload</a>';