forked from PHPSocialNetwork/phpfastcache
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagsMethods.php
More file actions
76 lines (61 loc) · 2.26 KB
/
tagsMethods.php
File metadata and controls
76 lines (61 loc) · 2.26 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
<?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) <[email protected]> https://www.phpfastcache.com
* @author Georges.L (Geolim4) <[email protected]>
*
*/
use Phpfastcache\CacheManager;
// Include composer autoloader
require __DIR__ . '/../../vendor/autoload.php';
$InstanceCache = CacheManager::getInstance('apc');
/**
* Try to get $products from Caching First
* product_page is "identity keyword";
*/
$key = "product_page";
$key2 = "product_page2";
$CachedString = $InstanceCache->getItem($key);
$CachedString2 = $InstanceCache->getItem($key2);
if (is_null($CachedString->get()) || is_null($CachedString2->get())) {
// Write products to Cache in 10 minutes with same keyword
$CachedString->set("My beautifull Ios product")
->expiresAfter(600)
->addTag('Mobile')
->addTag('Ios');
$CachedString2->set("My beautifull Android product")
->expiresAfter(600)
->addTag('Mobile')
->addTag('Android');
$InstanceCache->save($CachedString);
$InstanceCache->save($CachedString2);
echo "FIRST LOAD // WROTE OBJECT TO CACHE // RELOAD THE PAGE AND SEE // ";
echo '<br />TAGS of product_page item: ' . $CachedString->getTagsAsString();
echo '<br />TAGS of product_page2 item: ' . $CachedString2->getTagsAsString();
} else {
echo "<br />READ FROM CACHE WITH TAGS 'Ios' // <br />";
echo '<pre>';
var_dump($InstanceCache->getItemsByTag('Ios'));// Will output product_page item
echo '</pre>';
echo "<br />READ FROM CACHE WITH TAGS 'Android' // <br />";
echo '<pre>';
var_dump($InstanceCache->getItemsByTag('Android'));// Will output product_page2 item
echo '</pre>';
echo "<br />READ FROM CACHE WITH TAGS 'Ios,Android' // <br />";
echo '<pre>';
var_dump($InstanceCache->getItemsByTags(['Ios', 'Android']));// Will output product_page and product_page2 item
echo '</pre>';
}
/**
* Finally you can delete by tags
*
* $InstanceCache->deleteItemsByTag('Ios');
* $InstanceCache->deleteItemsByTags(['Ios', 'Android']);
**/
echo '<br /><br /><a href="/">Back to index</a> -- <a href="./' . basename(__FILE__) . '">Reload</a>';