dwi-wijonarko/laravel-simple-cache
Composer 安装命令:
composer require dwi-wijonarko/laravel-simple-cache
包简介
Simple cache management for Laravel with tags, warming, and monitoring dashboard
README 文档
README
A simple and elegant cache management package for Laravel with tag support, cache warming, pattern-based clearing, and a beautiful monitoring dashboard.
Features
- 🏷️ Tag-based caching - Organize and clear cache by tags
- 🔥 Cache warming - Pre-load cache with predefined data
- 🎯 Pattern clearing - Clear multiple cache keys using Redis patterns
- 📊 Dashboard - Beautiful web interface to monitor and manage cache
- 🛠️ Artisan commands - CLI tools for cache management
- 🔌 Trait support - Easy integration with Eloquent models
- 📝 Helper functions - Convenient global helpers
- 🚀 Fluent API - Chainable methods for clean code
Requirements
- PHP 8.0 or higher
- Laravel 9.x, 10.x, or 11.x
- Redis (optional, for advanced features)
Installation
Install the package via Composer:
composer require dwi-wijonarko/laravel-simple-cache
Publish the configuration file:
php artisan vendor:publish --tag=simple-cache-config
Optionally, publish the views:
php artisan vendor:publish --tag=simple-cache-views
Configuration
The configuration file config/simple-cache.php contains:
return [ 'default_ttl' => 3600, // Default cache TTL in seconds 'auto_clear_on_save' => true, // Auto clear cache on model save 'auto_clear_on_delete' => true, // Auto clear cache on model delete 'dashboard_enabled' => true, // Enable/disable dashboard 'dashboard_route' => 'cache-dashboard', // Dashboard route 'dashboard_middleware' => ['web', 'auth'], // Dashboard middleware 'warmers' => [], // Cache warmers configuration ];
Usage
Basic Usage
use DwiWijonarko\SimpleCache\Facades\CacheManager; // Store cache CacheManager::put('key', 'value', 3600); // Retrieve cache $value = CacheManager::get('key'); // Remember cache $users = CacheManager::remember('users', function () { return User::all(); }, 3600); // Forget cache CacheManager::forget('key');
Tagged Cache
// Store with tags CacheManager::tags(['users', 'active']) ->put('active_users', $users, 3600); // Retrieve with tags $users = CacheManager::tags(['users', 'active']) ->get('active_users'); // Clear by tags CacheManager::tags(['users'])->flush();
Cache Warming
Define warmers in config/simple-cache.php:
'warmers' => [ 'homepage:stats' => [ 'callback' => fn() => [ 'users' => User::count(), 'posts' => Post::count(), ], 'tags' => ['homepage', 'stats'], 'ttl' => 3600, ], ],
Warm cache via command:
php artisan cache:warm php artisan cache:warm --force
Pattern-based Clearing (Redis only)
// Clear all user cache keys CacheManager::clearByPattern('users:*');
Model Integration
Use the Cacheable trait in your models:
use DwiWijonarko\SimpleCache\Traits\Cacheable; class User extends Model { use Cacheable; protected $cachePrefix = 'user'; protected $cacheTags = ['users']; protected $cacheTtl = 3600; } // Usage $users = User::cached(); $user->cacheModel(); $user->clearCache();
Helper Functions
// Get cache manager instance $cache = simple_cache(); // Tagged cache helper cache_tags(['users', 'active'])->put('key', 'value');
Artisan Commands
# Display cache statistics php artisan cache:stats # Clear cache by tag php artisan cache:clear-tag users posts # Warm cache php artisan cache:warm php artisan cache:warm --force
Dashboard
Access the cache dashboard at: http://your-app.test/cache-dashboard
The dashboard provides:
- Real-time cache statistics
- Clear cache by tag
- Clear cache by pattern (Redis)
- Warm cache button
Configure dashboard access in config/simple-cache.php:
'dashboard_enabled' => true, 'dashboard_route' => 'cache-dashboard', 'dashboard_middleware' => ['web', 'auth'],
API Reference
CacheManager Methods
// Chainable configuration ->tags(array|string $tags) ->ttl(int $seconds) ->store(string $store) // Cache operations ->remember(string $key, Closure $callback, int $ttl = null) ->rememberForever(string $key, Closure $callback) ->put(string $key, $value, int $ttl = null) ->get(string $key, $default = null) ->has(string $key) ->forget(string $key) ->flush() // Advanced operations ->clearByPattern(string $pattern) ->warm(array $warmers) ->stats()
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Security
If you discover any security-related issues, please email dwi.wijonarko@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Support
For support, please open an issue on GitHub.
dwi-wijonarko/laravel-simple-cache 适用场景与选型建议
dwi-wijonarko/laravel-simple-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「redis」 「cache」 「tags」 「laravel」 「cache-manager」 「cache-warming」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dwi-wijonarko/laravel-simple-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dwi-wijonarko/laravel-simple-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dwi-wijonarko/laravel-simple-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A powerfull cacher based on laravels file cache driver
Microservice RPC through message queues.
Phalcon PHP Meta tags service
The CodeIgniter Redis package
贝嘟分布式缓存扩展
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-11