miradnan/laravel-model-caching
Pros:
QueryCacheable, TableCacheable) for opt-in adoption, preserving existing model logic.where, orderBy, limit), aligning with Laravel’s query-first paradigm.Cons:
dependents suggests niche or abandoned adoption.new Model constructor in examples). May require polyfills or forks for Laravel 9+/10+.$cacheFor as a property (could clash with existing model properties).Illuminate\Database\Eloquent\Model directly (no namespace abstraction).query() method or Builder internals may have changed since 2020, breaking SQL key generation.Cache or DB could conflict.cache()->tags()). Manual invalidation required for related models.TableCacheable) could lead to large cache entries for high-cardinality data.get() results may not mitigate N+1 issues for eager-loaded relationships.where('id', $dynamicId)) may generate inconsistent cache keys.SoftDeletes trait or withTrashed() queries.where('id', 1) vs. where('id', 2)) handled?Post belongs to User)?laravel-query-cache (active) or spatie/laravel-query-builder (for caching) be better fits?User::where('role', 'admin')->get()).Post, Product with static queries).QueryCacheable for high-impact, low-churn queries (e.g., dashboard widgets).TableCacheable sparingly (monitor memory usage).cacheFor conservatively (e.g., 60s).Post::updated() events).Builder modifications).getQuery() or toSql() if SQL key generation fails.Model constructor changes.create_function).cacheFor (start with 5–30s TTL).class Post extends Model {
use \miradnan\QueryCache\Traits\QueryCacheable;
public $cacheFor = 60; // 1 minute
}
Post::updated(fn ($post) => cache()->forget("query:posts:wherePublished:1"));
DB::enableQueryLog() to identify caching wins.cacheFor based on data volatility.cacheFor TTLs managed per model.query:posts:published) for granular control.cache()->flush()).cache()->getStore()->get()).TableCacheable can bloat cache with large datasets.How can I help you explore Laravel packages today?