jrumbut/eloquent-memoize is a Laravel package for memoization for eloquent (laravel) models.
It currently has 8 GitHub stars and 7.484 downloads on Packagist (latest version v0.1.1).
Install it with composer require jrumbut/eloquent-memoize.
Discover more Laravel packages by jrumbut
or browse all Laravel packages to compare alternatives.
Last updated
Memoization for Eloquent models.
Via Composer
$ composer require jrumbut/eloquent-memoize
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);
}
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.