File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ /**
3+ *
4+ * This file is part of phpFastCache.
5+ *
6+ * @license MIT License (MIT)
7+ *
8+ * For full copyright and license information, please see the docs/CREDITS.txt file.
9+ *
10+ * @author Khoa Bui (khoaofgod) <[email protected] > http://www.phpfastcache.com 11+ * @author Georges.L (Geolim4) <[email protected] > 12+ *
13+ */
14+ use phpFastCache \CacheManager ;
15+
16+ // Include composer autoloader
17+ require __DIR__ . '/../../vendor/autoload.php ' ;
18+
19+ $ InstanceCache = CacheManager::getInstance ('files ' );
20+ $ InstanceCache ->clear ();
21+
22+ /**
23+ * @var $keys \phpFastCache\Core\Item\ExtendedCacheItemInterface[]
24+ */
25+ $ keyPrefix = "product_page_ " ;
26+ $ keys = [];
27+
28+ for ($ i =1 ;$ i <=10 ;$ i ++)
29+ {
30+ $ keys [$ keyPrefix . $ i ] = $ InstanceCache ->getItem ($ keyPrefix . $ i );
31+ if (!$ keys [$ keyPrefix . $ i ]->isHit ()){
32+ $ keys [$ keyPrefix . $ i ]
33+ ->set (uniqid ('pfc ' , true ))
34+ ->addTag ('pfc ' );
35+ }
36+ }
37+
38+ $ InstanceCache ->saveMultiple ($ keys );
39+
40+ /**
41+ * Remove items references from memory
42+ */
43+ unset($ keys );
44+ $ InstanceCache ->detachAllItems ();
45+ gc_collect_cycles ();
46+
47+
48+ /**
49+ * Now get the items by a specific tag
50+ */
51+ $ keys = $ InstanceCache ->getItemsByTag ('pfc ' );
52+ foreach ($ keys as $ key ) {
53+ echo "Key: {$ key ->getKey ()} => {$ key ->get ()}<br /> " ;
54+ }
55+
56+ echo '<br /><br /><a href="/">Back to index</a> -- <a href="./ ' . basename (__FILE__ ) . '">Reload</a> ' ;
You can’t perform that action at this time.
0 commit comments