gregwar/cache
gregwar/cache is a lightweight PHP caching library with a simple API for caching values and function results. Supports multiple backends (filesystem, APC/APCu, memcache), TTL expiration, cache namespaces/prefixes, and easy integration into existing apps.
gregwar/cache package provides a lightweight, filesystem-based caching layer, ideal for scenarios requiring simple, persistent key-value storage without external dependencies (e.g., Redis, Memcached). It fits well in:
file, database) already abstract filesystem caching, but gregwar/cache offers:
CacheInterface), enabling seamless integration with Laravel’s Cache facade via a custom driver.Illuminate\Contracts\Cache\Store to Gregwar\Cache\Cache).file driver.flock() or Laravel’s cache locking.du -sh or custom logging.find /cache -type f -mtime +7 -delete).json or php serializers cautiously.CacheStoreEvents (e.g., cached, cleared). Implement listeners manually if needed.file Driver?
gregwar/cache offer features missing in Laravel’s driver (e.g., custom serializers, tagging)?file cache driver for custom serialization or legacy systems.CacheItemPoolInterface).config(['cache.default' => 'file']) for simplicity.symfony/cache (more feature-rich).gregwar/cache vs. Laravel’s file driver for your workload.Gregwar\Cache\Cache.// app/Providers/AppServiceProvider.php
use Gregwar\Cache\Cache;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
public function register() {
$this->app->bind('gregwar.cache', function() {
return new Cache(storage_path('framework/cache/gregwar'));
});
$this->app->bind('cache.driver', function($app) {
return $app['gregwar.cache'];
});
}
}
config/cache.php to use the new driver:
'drivers' => [
'gregwar' => [
'driver' => 'gregwar.cache',
'path' => storage_path('framework/cache/gregwar'),
'serializer' => 'json', // or 'php', 'custom'
],
],
cache()->store('file') as a fallback in the driver implementation:
public function get($key, $default = null) {
try {
return $this->gregwarCache->get($key, $default);
} catch (\Exception $e) {
return app('cache')->store('file')->get($key, $default);
}
}
Illuminate\Contracts\Cache\Store but not Psr\Cache\CacheItemPoolInterface. Use only for simple key-value caching.json, php, and custom serializers. Choose based on:
storage/app/cache/gregwar) with proper permissions (chmod 755).config/cache.php.du -sh /path/to/cache).time php artisan cache:clear).www-data) has write access to the cache directory.find /path/to/cache -type f -mtime +7 -delete
How can I help you explore Laravel packages today?