Eloquent Faster
Simple none-I/O cache for eloquent model accessor and mutators., (*1)
, (*2)
Installation
composer require "reshadman/eloquent-faster"
Usage
First you need to add the following service provider to your application, (*3)
return [
//.. other config
'providers' => [
// other providers
\Reshadman\EloquentFaster\EloquentFasterServiceProvider::class
]
];
Then run the following artisan command, (*4)
php artisan eloquent:cache
For clearing cache, (*5)
php artisan eloquent:clear
If you use OPCACHE in your PHP installation, this class will not use I/O for each script run, as opcache loads code into memory., (*6)
Problem
Simply the problem begins from this issuge., (*7)
Currently the eloquent model class contains a cache strategy for getters which first fetches all class methods and runs a loop on them filtering them by a regular expression.
This occurs only once per unique eloquent final object.
The getter cache container is only filled up with the processed snake case attribute key., (*8)
Each time a new model class is created for first time a loop with 50 to 100 iterations with processing a regular expression is run., (*9)
Wouldn't it be cool to have something like php artisan eloquent:cache
for this ?, (*10)
Running unit tests
Clone the repo, (*11)
git clone git@github.com:reshadman/eloquent-faster.git
Then run composer update
, (*12)
Now you can run phpunit in the repo folder., (*13)
vendor/bin/phpunit