jrumbut/eloquent-memoize

Memoization for Eloquent (Laravel) Models

v0.1.1 2018-08-29 00:26 UTC

This package is not auto-updated.

Last update: 2024-04-13 16:45:51 UTC


README

Latest Version on Packagist Software License Coverage Status Quality Score Total Downloads SensioLabsInsight

Memoization for Eloquent models.

Install

Via Composer

$ composer require jrumbut/eloquent-memoize

Usage

class MyModel extends MemoizingModel
{
    protected static $memoized = ['slow_attribute'];

    //Now only slow the first time it's accessed
    public function getSlowAttribute($value)
    {
        sleep(3);
        return ucwords($value);
    }
}

-or-

class TraitModel extends Model
{
    use Memoizes;
    
    /**
     * Initialize attributes
     *
     * @return void
     */
    public static function boot()
    {
        parent::boot();
        static::setMemoized(['slow']);
    }

    //Now only slow the first time it's accessed
    public function getSlowAttribute($value)
    {
        sleep(3);
        return ucwords($value);
    }
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email joshua.rumbut@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.