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

Laravel Cachable Attributes Laravel Package

astrotomic/laravel-cachable-attributes

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Performance Optimization: Justifies investing in caching expensive computed attributes (e.g., aggregations, external API calls, or complex calculations) to reduce database load and improve response times.
  • Build vs. Buy: Avoids reinventing caching logic for Eloquent accessors, reducing dev time and technical debt.
  • Roadmap Prioritization: Validates caching as a scalable solution for high-traffic features (e.g., dashboards, analytics, or real-time data displays) before considering more complex solutions (e.g., Redis-based materialized views).
  • Use Cases:
    • Caching derived attributes (e.g., user->totalOrders, product->avgRating).
    • Offloading expensive computations (e.g., geospatial calculations, NLP processing).
    • Reducing read-heavy database queries in read models or reporting tools.

When to Consider This Package

  • Adopt When:

    • Your Laravel app has repeatedly expensive accessors (e.g., >50ms per call) that hit the database or external services.
    • You’re using Eloquent models and want a lightweight, declarative caching layer.
    • Your team lacks expertise in custom caching implementations (e.g., Redis/Laravel Cache API).
    • You need TTL-based invalidation (e.g., cache refreshes on model updates).
    • The package’s MIT license aligns with your open-source policy.
  • Look Elsewhere If:

    • You need multi-model caching (e.g., caching relationships across multiple tables) → Consider Laravel Caching or Predis.
    • Your accessors require complex dependencies (e.g., real-time updates) → Evaluate event-driven caching (e.g., Laravel Echo + Redis pub/sub).
    • You’re using non-Eloquent models (e.g., raw queries, API clients) → Build custom caching logic.
    • Your app has strict consistency requirements (e.g., financial transactions) → Avoid caching or use short TTLs.
    • You need scalability beyond Laravel (e.g., microservices) → Consider dedicated caching layers like Memcached or Redis with a library like Spatie’s Laravel Cache.

How to Pitch It (Stakeholders)

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:

  • Simplicity: One trait replaces manual caching boilerplate.
  • Flexibility: Works with Laravel’s default cache drivers (file, database, Redis).
  • Maintainability: MIT-licensed, actively maintained (last release: 2023), and integrates seamlessly with Eloquent. Use case: Add @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:

  • No manual cache key management.
  • Automatic invalidation on model updates.
  • Works with any Laravel cache driver. Cons:
  • Limited to Eloquent models.
  • TTL granularity is per-accessor (not per-model). Best for: Expensive, read-heavy accessors where stale data is acceptable (e.g., dashboards, reports)."*
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