-
-
Save tanthammar/888a2cdee62220ee29a211556b87726c to your computer and use it in GitHub Desktop.
Revisions
-
paulund revised this gist
Sep 12, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,6 +28,6 @@ public function __construct(HasherContract $hasher) */ public function retrieveById($identifier) { return Cache::get("user.$identifier") ?? parent::retrieveById($identifier); } } -
paulund revised this gist
Sep 23, 2019 . No changes.There are no files selected for viewing
-
paulund revised this gist
Jun 9, 2018 . 1 changed file with 0 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -34,9 +34,6 @@ public function restored(User $user) } /** * @param User $user */ public function retrieved(User $user) -
paulund revised this gist
Jun 3, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ // Config/auth.php 'providers' => [ 'users' => [ 'driver' => 'cache-user', -
paulund revised this gist
Jun 3, 2018 . 4 changed files with 114 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ <?php namespace App\Providers; use App\Models\User; use App\Observers\UserObserver; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { /** * Bootstrap any application services. * * @return void */ public function boot() { User::observe(UserObserver::class); } /** * Register any application services. * * @return void */ public function register() { // } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ <?php namespace App\Providers; use App\Auth\CacheUserProvider; use Illuminate\Support\Facades\Auth; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { /** * The policy mappings for the application. * * @var array */ protected $policies = [ ]; /** * Register any authentication / authorization services. * * @return void */ public function boot() { // Caching user Auth::provider('cache-user', function() { return resolve(CacheUserProvider::class); }); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ <?php namespace App\Observers; use Illuminate\Foundation\Auth\User; use Illuminate\Support\Facades\Cache; /** * User observer */ class UserObserver { /** * @param User $user */ public function saved(User $user) { Cache::put("user.{$user->id}", $user, 60); } /** * @param User $user */ public function deleted(User $user) { Cache::forget("user.{$user->id}"); } /** * @param User $user */ public function restored(User $user) { Cache::put("user.{$user->id}", $user, 60); } /** * Listen to the User retrieved event. If this happens, the * user isn't cached, so we will cache it for next time. * * @param User $user */ public function retrieved(User $user) { Cache::add("user.{$user->id}", $user, 60); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ 'providers' => [ 'users' => [ 'driver' => 'cache-user', 'model' => App\Models\User::class, ] ] -
paulund created this gist
Jun 3, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <?php namespace App\Auth; use App\Models\User; use Illuminate\Auth\EloquentUserProvider; use Illuminate\Contracts\Hashing\Hasher as HasherContract; use Illuminate\Support\Facades\Cache; /** * Class CacheUserProvider * @package App\Auth */ class CacheUserProvider extends EloquentUserProvider { /** * CacheUserProvider constructor. * @param HasherContract $hasher */ public function __construct(HasherContract $hasher) { parent::__construct($hasher, User::class); } /** * @param mixed $identifier * @return \Illuminate\Contracts\Auth\Authenticatable|null */ public function retrieveById($identifier) { return Cache::get("user.$identifier") ?? parent::retrieveById($identifier; } }