A Laravel package that allows you to list, search and delete individual cache keys without having to purge the entire cache. Supports multiple cache drivers (Redis, File, Database) with an interactive command line interface.
You can install the package via composer:
composer require abr4xas/cache-ui-laravelOptionally, you can publish the config file with:
php artisan vendor:publish --tag="cache-ui-laravel-config"After publishing the config file, you can customize the package behavior:
return [
// Default cache store to use
'default_store' => env('CACHE_UI_DEFAULT_STORE', null),
// Character limit in value preview
'preview_limit' => env('CACHE_UI_PREVIEW_LIMIT', 100),
// Number of visible items in scroll
'search_scroll' => env('CACHE_UI_SEARCH_SCROLL', 15),
];You can also configure these values in your .env file:
CACHE_UI_DEFAULT_STORE=redis
CACHE_UI_PREVIEW_LIMIT=150
CACHE_UI_SEARCH_SCROLL=20For the best experience with file cache, you can use our custom key-aware-file driver that allows Cache UI to display real keys instead of file hashes.
- Add the custom store to your
config/cache.phpfile:
// ... existing code ...
'stores' => [
// ... existing stores ...
'file' => [
'driver' => 'key-aware-file', // Changed from 'file' to 'key-aware-file'
'path' => storage_path('framework/cache/data'),
'lock_path' => storage_path('framework/cache/data'),
],
// ... existing code ...- Register the custom driver in your
AppServiceProvider:
<?php
namespace App\Providers;
use Abr4xas\CacheUiLaravel\KeyAwareFileStore;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// Register the custom file cache driver
Cache::extend('key-aware-file', function ($app, $config) {
return Cache::repository(new KeyAwareFileStore(
$app['files'],
$config['path'],
$config['file_permission'] ?? null
));
});
}
}- β Readable keys: Shows real keys instead of file hashes
- β
Full compatibility: Works exactly like the standard
filedriver - β Better experience: Enables more intuitive cache key search and management
- β Backward compatibility: Existing cache files continue to work
If you already have cached data with the standard file driver, don't worry. The key-aware-file driver is fully compatible and:
- Existing data will continue to work normally
- New keys will be stored in the new format
- You can migrate gradually without data loss
Run the command to list and manage cache keys:
php artisan cache:listIf you have multiple cache stores configured, you can specify which one to use:
php artisan cache:list --store=redis- π Interactive search: Search cache keys by typing text
- π List all keys: View all available keys in your cache
- ποΈ Selective deletion: Delete individual keys without affecting the rest of the cache
- π Multiple drivers: Supports Redis, File and Database
- β Redis: Lists all keys using Redis KEYS command
- β File: Reads cache files from the filesystem
- β Database: Queries the cache table in the database
β οΈ Array: Not supported (array driver doesn't persist between requests)β οΈ Memcached: Not currently supported
$ php artisan cache:list
π¦ Cache driver: redis
β
Found 23 cache keys
π Search and select a cache key to delete
> user_1_profile
π Key: user_1_profile
Are you sure you want to delete this cache key? βΊ No / Yes
ποΈ The key 'user_1_profile' has been successfully deletedYou can also use the CacheUiLaravel class directly in your code:
use Abr4xas\CacheUiLaravel\Facades\CacheUiLaravel;
// Get all cache keys from default store
$keys = CacheUiLaravel::getAllKeys();
// Get all cache keys from a specific store
$redisKeys = CacheUiLaravel::getAllKeys('redis');
// Delete a specific key from default store
$deleted = CacheUiLaravel::forgetKey('user_1_profile');
// Delete a key from a specific store
$deleted = CacheUiLaravel::forgetKey('session_data', 'redis');composer test:unitThe following tests need to be implemented to fully validate the new KeyAwareFileStore functionality:
- Test
put()method with various data types (string, integer, array, boolean, null) - Test
get()method with wrapped and unwrapped data formats - Test
add()method behavior and return values - Test
forever()method with zero expiration - Test
increment()method with numeric values - Test backward compatibility with legacy cache files
- Test error handling for corrupted cache files
- Test file permissions and directory creation
- Test complete cache workflow (store β retrieve β delete)
- Test multiple keys with different expiration times
- Test cache key listing with
getAllKeys()method - Test cache key deletion with
forgetKey()method - Test mixed wrapped and legacy data scenarios
- Test performance with large numbers of cache keys
- Test custom driver registration in
AppServiceProvider - Test driver configuration with different file permissions
- Test driver fallback behavior with missing configuration
- Test driver isolation between different cache stores
- Test error handling for invalid paths and permissions
- Test
getAllKeys()method withkey-aware-filedriver - Test
forgetKey()method withkey-aware-filedriver - Test mixed driver scenarios (Redis + File + Database)
- Test error handling and graceful degradation
- Test with read-only file systems
- Test with insufficient disk space
- Test with invalid serialized data
- Test with very large cache values
- Test with special characters in cache keys
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.