astrotomic/laravel-cachable-attributes
user->totalOrders, product->avgRating).Adopt When:
Look Elsewhere If:
For Executives: "This package lets us cache computationally expensive data (e.g., user metrics, product analytics) without rewriting caching logic. For example, if a dashboard query takes 200ms to compute, we could reduce it to 10ms with a 5-minute cache—improving load times and cutting server costs. It’s a low-risk, high-reward optimization for performance-critical features, with minimal dev overhead."
For Engineering:
*"Leveraging astrotomic/laravel-cachable-attributes gives us a battle-tested trait to cache Eloquent accessors with TTL support. Key benefits:
@cacheable to accessors like getTotalSpent() to auto-cache results for 1 hour, invalidating on model updates. Tradeoff: ~10ms setup per accessor vs. hours of custom caching code."*For Developers:
*"This package lets you annotate Eloquent accessors with @cacheable to automatically cache their results. For example:
use Astrotomic\CacheableAttributes\CacheableAttribute;
class User extends Model {
use CacheableAttribute;
public function getFullName(): string
{
return $this->cacheable(fn () => $this->first_name . ' ' . $this->last_name, ttl: 60);
}
}
Pros:
How can I help you explore Laravel packages today?