-
Notifications
You must be signed in to change notification settings - Fork 387
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1934 from HDInnovations/Cache-Auth-User
(Add) Auth User Caching
- Loading branch information
Showing
7 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* NOTICE OF LICENSE. | ||
* | ||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 | ||
* The details is bundled with this project in the file LICENSE.txt. | ||
* | ||
* @project UNIT3D Community Edition | ||
* | ||
* @author HDVinnie <[email protected]> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Helpers; | ||
|
||
use App\Models\User; | ||
|
||
class CacheUser | ||
{ | ||
public static function user($id) | ||
{ | ||
if (! $id || $id <= 0 || ! is_numeric($id)) { | ||
return; | ||
} | ||
|
||
return \cache()->remember('cachedUser.'.$id, 30, function () use ($id) { | ||
return User::find($id); | ||
}); | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* NOTICE OF LICENSE. | ||
* | ||
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0 | ||
* The details is bundled with this project in the file LICENSE.txt. | ||
* | ||
* @project UNIT3D Community Edition | ||
* | ||
* @author HDVinnie <[email protected]> | ||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 | ||
*/ | ||
|
||
namespace App\Providers; | ||
|
||
use App\Helpers\CacheUser; | ||
use App\Models\User; | ||
use Illuminate\Auth\EloquentUserProvider; | ||
use Illuminate\Contracts\Hashing\Hasher as HasherContract; | ||
|
||
class CacheUserProvider extends EloquentUserProvider | ||
{ | ||
public function __construct(HasherContract $hasher) | ||
{ | ||
parent::__construct($hasher, User::class); | ||
} | ||
|
||
public function retrieveById($identifier) | ||
{ | ||
return CacheUser::user($identifier); | ||
} | ||
|
||
public function retrieveByToken($identifier, $token) | ||
{ | ||
$model = CacheUser::user($identifier); | ||
|
||
if (! $model) { | ||
return null; | ||
} | ||
|
||
$rememberToken = $model->getRememberToken(); | ||
|
||
return $rememberToken && hash_equals($rememberToken, $token) ? $model : null; | ||
} | ||
} |
This file contains 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 characters
This file contains 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 characters