@@ -126,7 +126,7 @@ public function test_invalidate_user_permissions_clears_cache_correctly()
126126 {
127127 // Cache user permissions
128128 $ this ->cacheService ->cacheUserPermissions ($ this ->userId , $ this ->userPermissions );
129- Cache:: put ( " user_ { $ this ->userId } _permissions " , $ this ->userPermissions , 3600 );
129+ $ this -> cacheService -> putLegacyUserPermissions ( $ this ->userId , $ this ->userPermissions , 3600 );
130130
131131 // Verify cache exists
132132 $ this ->assertNotNull (Cache::get ("user_permissions: {$ this ->userId }" ));
@@ -165,22 +165,44 @@ public function test_clear_all_clears_all_permission_caches()
165165 {
166166 // Cache both user and group permissions
167167 $ this ->cacheService ->cacheUserPermissions ($ this ->userId , $ this ->userPermissions );
168+ $ this ->cacheService ->putLegacyUserPermissions ($ this ->userId , $ this ->userPermissions , 3600 );
168169 $ this ->cacheService ->cacheGroupPermissions ($ this ->groupId , $ this ->groupPermissions );
169170 Cache::put ('unrelated-cache-key ' , 'keep-me ' , 3600 );
170171
171172 // Verify both caches exist
172173 $ this ->assertNotNull (Cache::get ("user_permissions: {$ this ->userId }" ));
174+ $ this ->assertNotNull (Cache::get ("user_ {$ this ->userId }_permissions " ));
173175 $ this ->assertNotNull (Cache::get ("group_permissions: {$ this ->groupId }" ));
174176
175177 // Clear all caches
176178 $ this ->cacheService ->clearAll ();
177179
178180 // Verify both caches were cleared
179181 $ this ->assertNull (Cache::get ("user_permissions: {$ this ->userId }" ));
182+ $ this ->assertNull (Cache::get ("user_ {$ this ->userId }_permissions " ));
180183 $ this ->assertNull (Cache::get ("group_permissions: {$ this ->groupId }" ));
181184 $ this ->assertSame ('keep-me ' , Cache::get ('unrelated-cache-key ' ));
182185 }
183186
187+ /**
188+ * Test that clearAll clears tracked legacy permission caches without touching unrelated cache.
189+ */
190+ public function test_clear_all_clears_legacy_user_permission_cache_only_when_tracked ()
191+ {
192+ $ permissions = $ this ->cacheService ->rememberLegacyUserPermissions ($ this ->userId , 3600 , function () {
193+ return $ this ->userPermissions ;
194+ });
195+ Cache::put ('unrelated-cache-key ' , 'keep-me ' , 3600 );
196+
197+ $ this ->assertEquals ($ this ->userPermissions , $ permissions );
198+ $ this ->assertNotNull (Cache::get ("user_ {$ this ->userId }_permissions " ));
199+
200+ $ this ->cacheService ->clearAll ();
201+
202+ $ this ->assertNull (Cache::get ("user_ {$ this ->userId }_permissions " ));
203+ $ this ->assertSame ('keep-me ' , Cache::get ('unrelated-cache-key ' ));
204+ }
205+
184206 /**
185207 * Test that cache keys are generated correctly
186208 */
0 commit comments