feat: 将用户登录信息与普通缓存数据区分存储

This commit is contained in:
augushong
2025-04-22 09:03:51 +08:00
parent c1042ce1c6
commit a078c14af7
3 changed files with 16 additions and 9 deletions

View File

@@ -1,4 +1,6 @@
<?php
use think\facade\App;
use think\facade\Env;
// +----------------------------------------------------------------------
@@ -10,20 +12,25 @@ return [
'default' => Env::get('cache.driver', 'file'),
// 缓存连接方式配置
'stores' => [
'stores' => [
'file' => [
// 驱动方式
'type' => 'File',
'type' => 'File',
// 缓存保存目录
'path' => '',
'path' => '',
// 缓存前缀
'prefix' => '',
'prefix' => '',
// 缓存有效期 0表示永久缓存
'expire' => 0,
'expire' => 0,
// 缓存标签前缀
'tag_prefix' => 'tag:',
// 序列化机制 例如 ['serialize', 'unserialize']
'serialize' => [],
'serialize' => [],
],
'login' => [
'type' => 'File',
// 缓存保存目录
'path' => App::getRuntimePath() . 'login/',
],
// 更多的缓存连接
],

View File

@@ -82,7 +82,7 @@ class LoginBase extends AdminController
$admin['expire_time'] = $post['keep_login'] == 1 ? true : time() + 7200;
session('admin', $admin);
$token = md5(uniqid());
Cache::set($token, $admin, $post['keep_login'] == 1 ? time() + 86400 * 7 : time() + 7200);
Cache::store('login')->set($token, $admin, $post['keep_login'] == 1 ? time() + 86400 * 7 : time() + 7200);
Session::delete('back-url');
$this->success('登录成功', ['token' => $token], $back_url);
@@ -102,7 +102,7 @@ class LoginBase extends AdminController
session('admin', null);
$token = $this->readHeaderToken();
if ($token) {
Cache::delete($token);
Cache::store('login')->delete($token);
}
$this->success('退出登录成功');
}

View File

@@ -188,7 +188,7 @@ function get_session_admin($key = null)
{
$token = read_header_token();
if (!empty($token)) {
$admin = Cache::get($token);
$admin = Cache::store('login')->get($token);
} else {
$admin = session('admin');
}