removed cache for existence of player

This commit is contained in:
Pig Fang 2020-01-12 11:58:34 +08:00
parent b816eb1c06
commit 1170a528d6
8 changed files with 2 additions and 106 deletions

View File

@ -365,7 +365,6 @@ class AdminController extends Controller
$cache = Option::form('cache', OptionForm::AUTO_DETECT, function ($form) {
$form->checkbox('enable_avatar_cache')->label();
$form->checkbox('enable_preview_cache')->label();
$form->checkbox('enable_notfound_cache', '404')->label();
})
->type('warning')
->addButton([

View File

@ -1,41 +0,0 @@
<?php
namespace App\Listeners;
use App\Events;
use App\Models\Player;
use Cache;
use Illuminate\Events\Dispatcher;
class CachePlayerExists
{
public function subscribe(Dispatcher $events)
{
$events->listen(Events\CheckPlayerExists::class, [$this, 'remember']);
$events->listen(Events\PlayerWasAdded::class, [$this, 'forget']);
}
public function remember($event)
{
$key = "notfound-{$event->playerName}";
if ($event->playerName && is_null(Cache::get($key))) {
$player = Player::where('name', $event->playerName)->first();
if (!$player) {
Cache::forever($key, '1');
return false;
} else {
return true;
}
} else {
return false;
}
}
public function forget($event)
{
Cache::forget("notfound-{$event->player->name}");
}
}

View File

@ -2,9 +2,6 @@
namespace App\Providers;
use App\Events;
use App\Listeners;
use Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
@ -36,18 +33,4 @@ class EventServiceProvider extends ServiceProvider
'App\Listeners\SerializeGlobals',
],
];
/**
* Register any other events for your application.
*
* @return void
*/
public function boot()
{
parent::boot();
if (option('enable_notfound_cache')) {
Event::subscribe(Listeners\CachePlayerExists::class);
}
}
}

View File

@ -206,5 +206,3 @@ cache:
enable_preview_cache:
title: Texture Preivew
label: Enable caching texture preivew
enable_notfound_cache:
label: Enable caching whether player is existed or not

View File

@ -67,6 +67,7 @@
- Removed Universal Skin API from core. (Install plugin if you need it.)
- Removed auto update check.
- Removed cache for Profile JSON.
- Removed cache for existence of player.
## Internal Changes

View File

@ -67,6 +67,7 @@
- 移除 Universal Skin API如有需要请安装插件
- 移除自动更新检查
- 移除对 Profile JSON 的缓存
- 移除对角色存在与否的缓存
## 内部更改

View File

@ -190,11 +190,9 @@ class AdminFormsTest extends BrowserKitTestCase
->see(trans('options.cache.driver', ['driver' => config('cache.default')]))
->check('enable_avatar_cache')
->check('enable_preview_cache')
->check('enable_notfound_cache')
->press('submit_cache');
$this->assertTrue(option('enable_avatar_cache'));
$this->assertTrue(option('enable_preview_cache'));
$this->assertTrue(option('enable_notfound_cache'));
Cache::shouldReceive('flush');
$this->visit('/admin/resource')

View File

@ -1,43 +0,0 @@
<?php
namespace Tests;
use App\Events;
use App\Models\Player;
use Cache;
use Event;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class CachePlayerExistsTest extends TestCase
{
use DatabaseTransactions;
public function setUp(): void
{
parent::setUp();
option(['enable_notfound_cache' => true]);
$provider = new \App\Providers\EventServiceProvider(app());
$provider->boot();
}
public function testRemember()
{
$player = factory(Player::class)->create();
Cache::shouldReceive('get')
->times(2)
->andReturn(null)
->andReturn(null);
Cache::shouldReceive('forever')->once()->with('notfound-nope', '1');
event(new Events\CheckPlayerExists(null));
event(new Events\CheckPlayerExists($player->name));
event(new Events\CheckPlayerExists('nope'));
}
public function testForget()
{
$player = factory(Player::class)->create();
event(new Events\PlayerWasAdded($player));
Cache::shouldReceive('forget')->with("notfound-{$player->name}");
}
}