hobbiot/cacheable-auth-user

Cache Auth::user() for Laravel 5.3. This package add new driver to laravel.
144 12
Install
composer require hobbiot/cacheable-auth-user
Latest Version:1.0.1
PHP:>=5.6.4
License:MIT
Last Updated:Jun 4, 2017
Links: GitHub  ·  Packagist
Maintainer: HobbIoT

cacheable-auth-user

Latest Stable Version Total Downloads Latest Unstable Version License

Cacheable Auth::user() for Laravel 5.3 or 5.4.

Installation

Composer

composer require hobbiot/cacheable-auth-user

Laravel

app.php

In your config/app.php add HobbIoT\Auth\CacheableAuthUserServiceProvider::class to the end of the providers array:

'providers' => [
    ...
        HobbIoT\Auth\CacheableAuthUserServiceProvider::class,
    ...
],

auth.php

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.

Supplementary Explanation

  • 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.

Related Packages

machaven/track-attempts

Track and limit any auth, OTP, or any other type of action.

4,020 3
fridzema/laravel-user-cache

Cache the laravel Auth::user()

212 2
ytake/laravel-voltdb

VoltDB providers for Laravel

37 4
barryvdh/laravel-httpcache

HttpCache for Laravel

407,264 502
kodeine/laravel-acl

Light-weight role-based permissions for Laravel 5 built in Auth system.

361,720 777