Commit b754f16b by 杨树贤

加缓存

parent 237c0daf
Showing with 8 additions and 0 deletions
......@@ -3,6 +3,7 @@
namespace App\Http\Middleware;
use App\Model\IntracodeModel;
use App\Model\RedisModel;
use App\Model\UserInfoModel;
use Closure;
use DB;
......@@ -100,12 +101,19 @@ class CheckLogin
public function getPerms()
{
$userId = request()->user->userId;
$cacheKey = 'supplier_perms_' . $userId;
$redis = new RedisModel();
$cachedPerms = $redis->get($cacheKey);
if ($cachedPerms !== null) {
return json_decode($cachedPerms, true);
}
$permsUrl = env('PERM_LIST') . '/' . $userId . '/' . env('PERM_ID') . '/';
$permsResult = json_decode(curl($permsUrl), true);
$perms = [];
if (isset($permsResult['retcode']) && $permsResult['retcode'] === 0) {
$perms = $permsResult['data']['perms'];
}
$redis->setex($cacheKey, 5, json_encode($perms));
return $perms;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment