Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Nova Laracache Laravel Package

mostafaznv/nova-laracache

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require mostafaznv/nova-laracache
    

    Publish the package configuration (if needed):

    php artisan vendor:publish --provider="Mostafaznv\NovaLaracache\NovaLaracacheServiceProvider"
    
  2. Register Tool: Add the tool to your Nova Tools section in app/Providers/NovaServiceProvider.php:

    public function tools()
    {
        return [
            \Mostafaznv\NovaLaracache\NovaLaracache::make(),
        ];
    }
    
  3. First Use Case:

    • Access the tool via Nova’s sidebar (under "Tools").
    • View all cached keys, their TTL (Time-To-Live), and stored values.
    • Use the built-in actions (e.g., "Delete," "Regenerate," or "Clear All") to manage cache entries directly from the UI.

Implementation Patterns

Core Workflows

  1. Cache Monitoring:

    • Pattern: Use the tool to audit cache usage across environments (dev/staging/prod).
    • Example: Filter keys by prefix (e.g., view::, session::) to isolate specific cache types.
    • Integration: Combine with Laravel’s Cache::getStore() to correlate UI insights with backend logic.
  2. TTL Management:

    • Pattern: Dynamically adjust TTLs for critical cache keys (e.g., user sessions, API responses).
    • Example: Override default TTLs via Nova’s "Edit" action, then sync changes with Cache::put($key, $value, $ttl).
  3. Bulk Operations:

    • Pattern: Use the "Clear All" or "Delete Selected" actions to reset caches during deployments or data migrations.
    • Integration: Trigger bulk operations via Nova’s Actions API (e.g., post-deployment hooks):
      Nova::serving(function () {
          NovaLaracache::clearAll();
      });
      
  4. Custom Cache Stores:

    • Pattern: Extend the tool to support non-default cache stores (e.g., Redis clusters, DynamoDB).
    • Implementation: Override the stores() method in NovaLaracache:
      public static function stores()
      {
          return [
              'redis' => 'Redis',
              'dynamodb' => 'DynamoDB',
          ];
      }
      
  5. Event-Driven Cache Updates:

    • Pattern: Listen for Nova events (e.g., Nova\Events\ToolWasUpdated) to auto-regenerate caches.
    • Example: Use Laravel’s Cache::forget() or Cache::put() in event listeners tied to model updates.

Gotchas and Tips

Pitfalls

  1. Performance Impact:

    • Issue: Fetching all cache keys (Cache::keys()) can be slow for large caches (e.g., >100K keys).
    • Fix: Implement pagination in the tool’s index() method or add a "Limit" filter.
  2. Serialization Errors:

    • Issue: Complex objects (e.g., Closures, Resources) may fail to serialize in the Nova UI.
    • Fix: Use json_encode()/json_decode() for values or extend the tool to handle custom serialization.
  3. Permission Conflicts:

    • Issue: Nova’s default gates may block cache operations for non-admin users.
    • Fix: Define custom gates in NovaServiceProvider:
      Gate::define('viewNovaLaracache', function ($user) {
          return $user->can('manage-cache');
      });
      
  4. Store-Specific Quirks:

    • Issue: Some stores (e.g., DynamoDB) may return truncated or formatted values.
    • Fix: Normalize output in the tool’s resolveValue() method:
      protected function resolveValue($value)
      {
          return is_string($value) ? json_decode($value, true) : $value;
      }
      

Debugging Tips

  1. Log Cache Operations:

    • Enable Laravel’s cache logging in config/cache.php:
      'default' => env('CACHE_DRIVER', 'file'),
      'stores' => [
          'file' => [
              'driver' => 'file',
              'log' => true, // Enable logging
          ],
      ],
      
    • Check storage/logs/laravel.log for cache-related entries.
  2. Test Locally First:

    • Use Cache::flush() to reset caches between tests and verify UI updates reflect changes.
  3. Leverage Nova’s DevTools:

    • Inspect the tool’s Blade templates (resources/views) to debug rendering issues.
    • Use Nova’s php artisan nova:serve to test changes in development.

Extension Points

  1. Custom Actions:

    • Add actions via the tool’s actions() method:
      public function actions(Request $request)
      {
          return [
              new \Mostafaznv\NovaLaracache\Actions\RegenerateCache($request),
              new CustomAction(), // Your custom action
          ];
      }
      
  2. Search Functionality:

    • Extend the tool to search cache keys by prefix or value:
      public function index(Request $request)
      {
          $keys = Cache::keys($request->input('search', '*'));
          return $this->withSearch($keys);
      }
      
  3. Cache Analytics:

    • Integrate with Laravel’s Cache::stats() (if supported by the store) to add hit/miss metrics to the tool’s dashboard.
  4. Multi-Tenancy:

    • Scope cache keys by tenant (e.g., tenant:{id}:key) and filter the tool’s output accordingly:
      $keys = Cache::keys("tenant:{$tenantId}:*");
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle