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

Phpfastcache Devtools Laravel Package

phpfastcache/phpfastcache-devtools

Internal development tools used by Phpfastcache and its extensions. Provides utilities to support building, testing, and maintaining Phpfastcache-related packages and workflows.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require phpfastcache/phpfastcache-devtools --dev
    

    Add to composer.json under require-dev to avoid production bloat.

  2. Basic Usage:

    use PHPSocialNetwork\Phpfastcache\DevTools\CacheAnalyzer;
    
    $analyzer = new CacheAnalyzer();
    $stats = $analyzer->analyzeCache('phpFastCache'); // Default driver
    dump($stats);
    
  3. First Use Case:

    • Debug Cache Hit/Miss Rates:
      $analyzer->enableMonitoring();
      // ... trigger cache operations ...
      $analyzer->getMonitoringData();
      
    • Check Cache Size:
      $size = $analyzer->getCacheSize('phpFastCache');
      

Where to Look First

  • CacheAnalyzer class: Core for stats and monitoring.
  • CacheMonitor class: Real-time hit/miss tracking.
  • CacheCleaner class: Tools for cache maintenance.
  • Documentation: Minimal, but inspect method signatures in src/ for usage.

Implementation Patterns

Workflows

  1. Pre-Deployment Cache Audit:

    $analyzer = new CacheAnalyzer();
    $report = $analyzer->generateReport(['phpFastCache']);
    // Log or email $report before deploy.
    
  2. Performance Profiling:

    $monitor = new CacheMonitor();
    $monitor->start();
    
    // ... critical cache operations ...
    $stats = $monitor->stop();
    if ($stats['miss_rate'] > 0.2) {
        // Trigger cache warming or optimization.
    }
    
  3. Automated Cache Cleanup:

    $cleaner = new CacheCleaner('phpFastCache');
    $cleaner->clearExpired(); // Remove stale entries.
    $cleaner->trimToSize(100); // Enforce size limit.
    

Integration Tips

  • Laravel Service Provider: Bind the analyzer to the container for global access:

    $this->app->singleton(CacheAnalyzer::class, function ($app) {
        return new CacheAnalyzer();
    });
    

    Then inject CacheAnalyzer into controllers/services.

  • Artisan Commands: Create a custom command for CLI access:

    use PHPSocialNetwork\Phpfastcache\DevTools\CacheAnalyzer;
    
    class CacheReportCommand extends Command {
        protected function handle() {
            $analyzer = new CacheAnalyzer();
            $this->info($analyzer->generateReport());
        }
    }
    
  • Middleware for Monitoring: Wrap cache-heavy routes to log performance:

    $monitor = new CacheMonitor();
    $monitor->start();
    
    // Route logic...
    $monitor->stop();
    $this->logMonitoringData($monitor);
    
  • Event Listeners: Trigger cache cleanup on cache:clear events or cron jobs:

    event(new CacheCleanupEvent());
    // Listener:
    public function handle(CacheCleanupEvent $event) {
        (new CacheCleaner('phpFastCache'))->clearExpired();
    }
    

Gotchas and Tips

Pitfalls

  1. Driver-Specific Quirks:

    • Not all drivers (e.g., files, apcu) support all methods. Test with your target driver.
    • Example: getCacheSize() may return null for apcu (use apcu_cache_info() instead).
  2. Monitoring Overhead:

    • Real-time monitoring (CacheMonitor) adds microsecond latency. Disable in production if unused:
      $monitor->enable(); // Default: true
      $monitor->disable();
      
  3. Race Conditions:

    • Concurrent cache operations may skew monitoring data. Use CacheMonitor sparingly in high-traffic areas.
  4. Dev-Only Methods:

    • Methods like generateReport() are heavy; avoid in production. Use only in staging/dev.

Debugging

  • Verify Driver Configuration: Ensure phpFastCache is properly configured in config/cache.php before using dev tools.

    'default' => env('CACHE_DRIVER', 'phpFastCache'),
    'stores' => [
        'phpFastCache' => [
            'driver' => 'phpFastCache',
            'items' => [
                'path' => storage_path('framework/cache'),
            ],
        ],
    ],
    
  • Check for Deprecated Methods: The package is new; some methods may change. Check the GitHub issues for updates.

  • Log Raw Data: For complex debugging, log raw stats:

    file_put_contents(
        storage_path('logs/cache_debug.log'),
        print_r($analyzer->analyzeCache(), true)
    );
    

Extension Points

  1. Custom Metrics: Extend CacheAnalyzer to add domain-specific metrics:

    class ExtendedAnalyzer extends CacheAnalyzer {
        public function getCustomMetric() {
            return $this->getMissRate() * $this->getAvgItemSize();
        }
    }
    
  2. Driver-Specific Adapters: Create adapters for unsupported drivers (e.g., Redis):

    class RedisCacheAnalyzer extends CacheAnalyzer {
        public function getCacheSize() {
            return redis()->dbsize();
        }
    }
    
  3. Event-Driven Cleanup: Subscribe to Laravel events to auto-clean cache:

    event(new CacheCleanupEvent());
    // Listener:
    public function handle() {
        (new CacheCleaner('phpFastCache'))->trimToSize(50);
    }
    
  4. Visualization: Integrate with tools like Grafana by exposing stats via an API:

    Route::get('/cache/stats', function () {
        return response()->json((new CacheAnalyzer())->analyzeCache());
    });
    
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport