1+ <?php
2+
3+ /**
4+ * @author Khoa Bui (khoaofgod) <[email protected] > http://www.phpfastcache.com 5+ * @author Georges.L (Geolim4) <[email protected] > 6+ */
7+
8+ use phpFastCache \CacheManager ;
9+ use phpFastCache \Helper \TestHelper ;
10+
11+ chdir (__DIR__ );
12+ require_once __DIR__ . '/../../vendor/autoload.php ' ;
13+
14+ /**
15+ * @param $obj
16+ * @param $prop
17+ * @return mixed
18+ * @throws \ReflectionException
19+ */
20+ function accessInaccessibleMember ($ obj , $ prop ) {
21+ $ reflection = new \ReflectionClass ($ obj );
22+ $ property = $ reflection ->getProperty ($ prop );
23+ $ property ->setAccessible (true );
24+ return $ property ->getValue ($ obj );
25+ }
26+
27+ // Hide php Redis extension notice by using a little @
28+ $ cacheInstance = CacheManager::getInstance ('Files ' );
29+ $ string = uniqid ('pfc ' , true );
30+
31+ /**
32+ * Populate the cache with some data
33+ */
34+ list ($ item , $ item2 ) = array_values ($ cacheInstance ->getItems (['item1 ' , 'item2 ' ]));
35+
36+ $ item ->set ($ string )
37+ ->addTags (['tag-all ' , 'tag1 ' ])
38+ ->expiresAfter (3600 );
39+
40+ $ item2 ->set ($ string )
41+ ->addTags (['tag-all ' , 'tag2 ' ])
42+ ->expiresAfter (3600 );
43+
44+ $ cacheInstance ->save ($ item );
45+ $ cacheInstance ->save ($ item2 );
46+ $ cacheInstance ->detachAllItems ();
47+ unset($ item , $ item2 );
48+
49+ /**
50+ * Destroy the populated items
51+ */
52+ $ cacheInstance ->deleteItemsByTag ('tag-all ' );
53+
54+ /**
55+ * First test memory, as we will write the item inside in the second test
56+ */
57+ $ itemInstances = accessInaccessibleMember ($ cacheInstance , 'itemInstances ' );
58+ if (isset ($ itemInstances [$ cacheInstance ::DRIVER_TAGS_KEY_PREFIX . 'tag-all ' ])) {
59+ echo '[FAIL] The internal cache item tag is still stored in memory ' . PHP_EOL ;
60+ } else {
61+ echo '[PASS] The internal cache item tag is no longer stored in memory ' . PHP_EOL ;
62+ }
63+
64+ /**
65+ * Then test disk to see if the item is still there
66+ */
67+ if ($ cacheInstance ->getItem ($ cacheInstance ::DRIVER_TAGS_KEY_PREFIX . 'tag-all ' )->isHit ()) {
68+ echo '[FAIL] The internal cache item tag is still stored on disk ' . PHP_EOL ;
69+ } else {
70+ echo '[PASS] The internal cache item tag is no longer stored on disk ' . PHP_EOL ;
71+ }
0 commit comments