@@ -16,6 +16,20 @@ class CacheStack
1616 */
1717 protected array $ keys = [];
1818
19+ /**
20+ * List of another caches
21+ *
22+ * @var array $another_caches
23+ */
24+ protected array $ another_caches = [];
25+
26+ /**
27+ * Default key for storing another caches
28+ *
29+ * @var string
30+ */
31+ protected string $ another_caches_key = 'slydeath:nc:ac ' ;
32+
1933 /**
2034 * Cache instance
2135 *
@@ -38,9 +52,53 @@ public function __construct(Caching $caching)
3852 *
3953 * @param string $key Caching key
4054 */
41- public function setKey (string $ key )
55+ public function setKey (string $ key ): CacheStack
4256 {
4357 $ this ->keys [] = $ key ;
58+
59+ return $ this ;
60+ }
61+
62+ /**
63+ * Add another key
64+ *
65+ * @param string $key Caching key
66+ */
67+ public function setAnotherKey (string $ key ): CacheStack
68+ {
69+ $ this ->another_caches_key = $ key ;
70+
71+ return $ this ;
72+ }
73+
74+ /**
75+ * Get a list of keys
76+ *
77+ * @return array
78+ */
79+ public function getKeys (): array
80+ {
81+ return $ this ->keys ;
82+ }
83+
84+ /**
85+ * Collect another caches
86+ *
87+ * @param array $data Another cache data
88+ */
89+ public function addAnotherCache (array $ data )
90+ {
91+ $ this ->another_caches [] = $ data ;
92+ }
93+
94+ /**
95+ * Get list of another caches
96+ *
97+ * @return mixed
98+ */
99+ public function getAnotherCaches ()
100+ {
101+ return \Cache::rememberForever ($ this ->another_caches_key , fn () => $ this ->another_caches );
44102 }
45103
46104 /**
@@ -62,12 +120,19 @@ public function clearCache($keys = null): bool
62120 }
63121
64122 /**
65- * Get a list of keys
66- *
67- * @return array
123+ * Clear another caches
68124 */
69- public function getKeys (): array
125+ public function clearAnotherCaches ()
70126 {
71- return $ this ->keys ;
127+ foreach ($ this ->getAnotherCaches () as $ cache ) {
128+ $ tags = data_get ($ cache , 'tags ' );
129+ $ key = data_get ($ cache , 'key ' );
130+
131+ if (count ($ tags )) {
132+ \Cache::tags ($ tags )->forget ($ key );
133+ } else {
134+ \Cache::forget ($ key );
135+ }
136+ }
72137 }
73138}
0 commit comments