clear cache of Me when logout
This commit is contained in:
parent
d95d78f5a2
commit
ad6d884437
3 changed files with 14 additions and 2 deletions
|
|
@ -64,6 +64,7 @@ class App
|
||||||
|
|
||||||
public static function unsetU(): void
|
public static function unsetU(): void
|
||||||
{
|
{
|
||||||
|
Redis::unsetMe($_COOKIE['u'] ?? '');
|
||||||
try {
|
try {
|
||||||
setcookie('u', null, [
|
setcookie('u', null, [
|
||||||
'expires' => time() - 3600,
|
'expires' => time() - 3600,
|
||||||
|
|
@ -128,8 +129,8 @@ HTML,
|
||||||
try {
|
try {
|
||||||
$u = static::getU();
|
$u = static::getU();
|
||||||
if ($u === null) return null;
|
if ($u === null) return null;
|
||||||
$cachedMe = Redis::getCachedMe($_COOKIE['u']);
|
$cachedMe = Redis::getCachedMe($_COOKIE['u'] ?? '');
|
||||||
if ($cachedMe === null) return Redis::cacheMe($_COOKIE['u'], Auth::getMe($u));
|
if ($cachedMe === null) return Redis::cacheMe($_COOKIE['u'] ?? '', Auth::getMe($u));
|
||||||
return $cachedMe;
|
return $cachedMe;
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
error_log('Failed to getMe.');
|
error_log('Failed to getMe.');
|
||||||
|
|
|
||||||
|
|
@ -51,4 +51,14 @@ class Redis
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function unsetMe(string $u): void
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$redis = static::connect();
|
||||||
|
$redis->unlink(static::getKey($u));
|
||||||
|
} catch (\RedisException $e) {
|
||||||
|
trigger_error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MingTsay\Akanyan\App;
|
use MingTsay\Akanyan\App;
|
||||||
|
use MingTsay\Akanyan\Redis;
|
||||||
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue