Package Data | |
---|---|
Maintainer Username: | HobbIoT |
Maintainer Contact: | dev@hobbiot.co.jp (HobbIoT) |
Package Create Date: | 2016-11-05 |
Package Last Update: | 2017-06-04 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-17 03:01:21 |
Package Statistics | |
---|---|
Total Downloads: | 144 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 14 |
Total Watchers: | 2 |
Total Forks: | 6 |
Total Open Issues: | 1 |
Cacheable Auth::user() for Laravel 5.3 or 5.4.
Composer
composer require hobbiot/cacheable-auth-user
In your config/app.php
add HobbIoT\Auth\CacheableAuthUserServiceProvider::class
to the end of the providers
array:
'providers' => [
...
HobbIoT\Auth\CacheableAuthUserServiceProvider::class,
...
],
In your config/auth.php
change User Providers' driver. You can now use "cacheableEloquent".
...
'providers' => [
'users' => [
'driver' => 'cacheableEloquent',
'model' => App\User::class,
],
// e.g.
'admin' => [
'driver' => 'cacheableEloquent',
'model' => App\Administrator::class,
],
],
...
],
Administrator::class needs to extend Authenticatable (Illuminate\Foundation\Auth\User) and use trait Notifiable (Illuminate\Notifications\Notifiable), just like App\User::class.
The cache is valid for 60 minutes.
The cache Key is ModelClassName_By_Id_id and ModelClassName_By_Id_Token_id.
Using Eloquent updated event listener to clear cache, need to use model->save()
. When user update his name in profile page,
fire updated event automatically, (listen event and) clear cache. After that reload from resources (database).
Laravel Official Documentation said,
Note: When issuing a mass update via Eloquent, the saved and updated model events will not be fired for the updated models. This is because the models are never actually retrieved when issuing a mass update.