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

Do File Cache Laravel Package

jord-jd/do-file-cache

Laravel file cache driver that stores cache entries as PHP “.do” files. Simple, fast, git-friendly caching for local/dev use, with easy setup and predictable files you can inspect, commit, or clear without a database.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require jord-jd/do-file-cache
    

    Register the service provider in config/app.php:

    'providers' => [
        // ...
        JordJd\DoFileCache\FileCacheServiceProvider::class,
    ],
    
  2. Basic Usage

    use JordJd\DoFileCache\Facades\FileCache;
    
    // Cache a value
    FileCache::put('key', 'value', 3600); // 1 hour TTL
    
    // Retrieve a value
    $value = FileCache::get('key');
    
    // Check if key exists
    if (FileCache::has('key')) {
        // ...
    }
    
  3. First Use Case Cache API responses or database queries in a Laravel controller:

    public function getData()
    {
        return FileCache::remember('api_data', 300, function () {
            return Http::get('https://api.example.com/data')->json();
        });
    }
    

Implementation Patterns

Common Workflows

  1. Cache-as-View

    // Cache a Blade view for 10 minutes
    FileCache::remember('dashboard_view', 600, function () {
        return view('dashboard')->render();
    });
    
  2. Tag-Based Invalidation

    // Cache with tags for granular invalidation
    FileCache::tags(['users', 'profile'])->put('user_profile', $userData, 3600);
    
    // Later, invalidate by tag
    FileCache::tags(['users'])->forget();
    
  3. Dependency Injection

    use JordJd\DoFileCache\Contracts\CacheInterface;
    
    public function __construct(CacheInterface $cache) {
        $this->cache = $cache;
    }
    

Integration Tips

  • Laravel Cache Store Register as a Laravel cache driver in config/cache.php:

    'stores' => [
        'file_cache' => [
            'driver' => 'jord-jd-file-cache',
            'path'   => storage_path('framework/cache'),
        ],
    ],
    

    Then use via Laravel’s cache facade:

    Cache::store('file_cache')->put('key', 'value', 3600);
    
  • Cache Events Listen for cache events (e.g., CacheHit, CacheMiss) via Laravel’s event system:

    event(new CacheHit($key, $value));
    
  • Fallback Logic Combine with Laravel’s cache:

    $value = Cache::remember('key', 3600, function () {
        return FileCache::get('fallback_key') ?? Http::get('...')->json();
    });
    

Gotchas and Tips

Pitfalls

  1. File Permissions Ensure the cache directory (storage/framework/cache by default) is writable:

    chmod -R 775 storage/framework/cache
    

    Debugging: Check for PermissionDeniedException if files aren’t writable.

  2. TTL Granularity The package uses seconds for TTL, not minutes (unlike some Laravel helpers).

    // ❌ Wrong (caches for 1 minute)
    FileCache::put('key', 'value', 1);
    
    // ✅ Correct (caches for 60 seconds)
    FileCache::put('key', 'value', 60);
    
  3. Tag Invalidation Race Conditions Tag-based invalidation (forget()) may not immediately clear all cached items due to file system latency. Workaround: Use FileCache::flush() for a full cache wipe if needed.

  4. Memory vs. Disk Tradeoff Large cached objects (e.g., serialized Blade views) may bloat disk storage. Tip: Use FileCache::rememberForever() sparingly for static assets.

Debugging

  • Cache Directory Inspection Manually check storage/framework/cache for stale files or corrupted entries.

    ls -la storage/framework/cache
    
  • Logging Enable debug mode in config/file-cache.php:

    'debug' => env('APP_DEBUG', false),
    

    Logs cache hits/misses to storage/logs/laravel.log.

  • Manual Cache Flush Clear the cache directory programmatically:

    FileCache::flush();
    

Extension Points

  1. Custom Cache Path Override the default path in config:

    'path' => storage_path('app/cache/custom'),
    
  2. File Naming Strategy Extend the FileCache class to customize key-to-file hashing:

    use JordJd\DoFileCache\Contracts\CacheInterface;
    
    class CustomCache implements CacheInterface {
        public function getFileName(string $key): string {
            return md5($key . '_custom_salt') . '.cache';
        }
        // ...
    }
    
  3. Compression Enable GZIP compression for large cached files:

    FileCache::compress(true)->put('large_data', $data, 3600);
    
  4. Event Hooks Subscribe to cache events in EventServiceProvider:

    protected $listen = [
        'JordJd\DoFileCache\Events\CacheHit' => [
            'App\Listeners\LogCacheHit',
        ],
    ];
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours