Installation:
composer require mostafaznv/nova-laracache
Publish the package configuration (if needed):
php artisan vendor:publish --provider="Mostafaznv\NovaLaracache\NovaLaracacheServiceProvider"
Register Tool:
Add the tool to your Nova Tools section in app/Providers/NovaServiceProvider.php:
public function tools()
{
return [
\Mostafaznv\NovaLaracache\NovaLaracache::make(),
];
}
First Use Case:
Cache Monitoring:
view::, session::) to isolate specific cache types.Cache::getStore() to correlate UI insights with backend logic.TTL Management:
Cache::put($key, $value, $ttl).Bulk Operations:
Nova::serving(function () {
NovaLaracache::clearAll();
});
Custom Cache Stores:
stores() method in NovaLaracache:
public static function stores()
{
return [
'redis' => 'Redis',
'dynamodb' => 'DynamoDB',
];
}
Event-Driven Cache Updates:
Nova\Events\ToolWasUpdated) to auto-regenerate caches.Cache::forget() or Cache::put() in event listeners tied to model updates.Performance Impact:
Cache::keys()) can be slow for large caches (e.g., >100K keys).index() method or add a "Limit" filter.Serialization Errors:
json_encode()/json_decode() for values or extend the tool to handle custom serialization.Permission Conflicts:
NovaServiceProvider:
Gate::define('viewNovaLaracache', function ($user) {
return $user->can('manage-cache');
});
Store-Specific Quirks:
resolveValue() method:
protected function resolveValue($value)
{
return is_string($value) ? json_decode($value, true) : $value;
}
Log Cache Operations:
config/cache.php:
'default' => env('CACHE_DRIVER', 'file'),
'stores' => [
'file' => [
'driver' => 'file',
'log' => true, // Enable logging
],
],
storage/logs/laravel.log for cache-related entries.Test Locally First:
Cache::flush() to reset caches between tests and verify UI updates reflect changes.Leverage Nova’s DevTools:
resources/views) to debug rendering issues.php artisan nova:serve to test changes in development.Custom Actions:
actions() method:
public function actions(Request $request)
{
return [
new \Mostafaznv\NovaLaracache\Actions\RegenerateCache($request),
new CustomAction(), // Your custom action
];
}
Search Functionality:
public function index(Request $request)
{
$keys = Cache::keys($request->input('search', '*'));
return $this->withSearch($keys);
}
Cache Analytics:
Cache::stats() (if supported by the store) to add hit/miss metrics to the tool’s dashboard.Multi-Tenancy:
tenant:{id}:key) and filter the tool’s output accordingly:
$keys = Cache::keys("tenant:{$tenantId}:*");
How can I help you explore Laravel packages today?