Skip to content

Commit df3b2c4

Browse files
committed
fix: file driver deletion bug and docs update
1 parent 72f979f commit df3b2c4

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ CACHE_UI_PREVIEW_LIMIT=150
5050
CACHE_UI_SEARCH_SCROLL=20
5151
```
5252

53-
### Custom File Cache Driver (Recommended)
53+
### Custom File Cache Driver (Only for File Store)
5454

55-
For 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.
55+
If you are using the `file` cache driver (default in Laravel), you should use our custom `key-aware-file` driver.
56+
57+
**Why?** The standard Laravel `file` driver stores keys as hashes, making them unreadable. This custom driver wraps the value to store the real key, allowing you to see and search for them.
58+
59+
> **Important**: This is **NOT** needed for Redis or Database drivers, as they support listing keys natively.
5660
5761
#### Driver Configuration
5862

@@ -84,6 +88,7 @@ namespace App\Providers;
8488
use Abr4xas\CacheUiLaravel\KeyAwareFileStore;
8589
use Illuminate\Support\Facades\Cache;
8690
use Illuminate\Support\ServiceProvider;
91+
use Illuminate\Foundation\Application;
8792

8893
class AppServiceProvider extends ServiceProvider
8994
{
@@ -101,13 +106,11 @@ class AppServiceProvider extends ServiceProvider
101106
public function boot(): void
102107
{
103108
// Register the custom file cache driver
104-
Cache::extend('key-aware-file', function ($app, $config) {
105-
return Cache::repository(new KeyAwareFileStore(
106-
$app['files'],
107-
$config['path'],
108-
$config['file_permission'] ?? null
109-
));
110-
});
109+
Cache::extend('key-aware-file', fn (Application $app, array $config) => Cache::repository(new KeyAwareFileStore(
110+
$app['files'],
111+
$config['path'],
112+
$config['file_permission'] ?? null
113+
)));
111114
}
112115
}
113116
```
@@ -156,11 +159,15 @@ php artisan cache:list --store=redis
156159

157160
### Supported Drivers
158161

159-
-**Redis**: Lists all keys using Redis KEYS command
160-
-**File**: Reads cache files from the filesystem
161-
-**Database**: Queries the cache table in the database
162-
- ⚠️ **Array**: Not supported (array driver doesn't persist between requests)
163-
- ⚠️ **Memcached**: Not currently supported
162+
| Driver | Support | Configuration Required |
163+
|--------|---------|------------------------|
164+
| **Redis** | ✅ Native | None (Works out of the box) |
165+
| **Database** | ✅ Native | None (Works out of the box) |
166+
| **File** | ✅ Enhanced | **Requires `key-aware-file` driver** |
167+
| **Array** | ⚠️ No | Not supported (doesn't persist) |
168+
| **Memcached** | ⚠️ No | Not currently supported |
169+
170+
> **Note**: The `key-aware-file` driver is **only** needed if you use the `file` cache driver. If you use Redis or Database, you don't need to change your driver configuration.
164171
165172
### Usage Example
166173

src/Commands/CacheUiLaravelCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public function handle(): int
9090
if (! $deleted && $this->driver === 'file') {
9191
// For file driver, try to delete using the actual key
9292
$deleted = $this->deleteFileKeyByKey($selectedKey);
93+
94+
if (! $deleted) {
95+
// If that fails, it might be a standard cache file where the key is the filename (hash)
96+
$deleted = $this->deleteFileKey($selectedKey);
97+
}
9398
}
9499

95100
if ($deleted) {

0 commit comments

Comments
 (0)