Move cache to a property, update cache key
This commit is contained in:
parent
dcf53f8b0f
commit
50d3fd71a6
|
@ -21,6 +21,11 @@ class PickWinnerCommand extends Command
|
||||||
*/
|
*/
|
||||||
private $client;
|
private $client;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Symfony\Contracts\Cache\CacheInterface
|
||||||
|
*/
|
||||||
|
private $cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \App\Service\Picker
|
* @var \App\Service\Picker
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +41,7 @@ class PickWinnerCommand extends Command
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->client = new Client();
|
$this->client = new Client();
|
||||||
|
$this->cache = new FilesystemCache();
|
||||||
$this->picker = $picker;
|
$this->picker = $picker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +75,9 @@ class PickWinnerCommand extends Command
|
||||||
'end date' => $endDate,
|
'end date' => $endDate,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// $io->success('You have a new command! Now make it your own! Pass --help to see your options.');
|
$cacheKey = md5(collect(['events:', $tag, $startDate, $endDate])->implode('_'));
|
||||||
$cache = new FilesystemCache();
|
|
||||||
$cacheKey = md5(collect([$tag, $startDate, $endDate])->implode('_'));
|
|
||||||
|
|
||||||
if (!$events = $cache->get($cacheKey)) {
|
if (!$events = $this->cache->get($cacheKey)) {
|
||||||
$response = $this->client->get('http://api.joind.in/v2.1/events', [
|
$response = $this->client->get('http://api.joind.in/v2.1/events', [
|
||||||
'query' => [
|
'query' => [
|
||||||
'tags' => [$tag],
|
'tags' => [$tag],
|
||||||
|
@ -83,7 +87,7 @@ class PickWinnerCommand extends Command
|
||||||
]
|
]
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$cache->set($cacheKey, json_decode($response->getBody())->events, 3600);
|
$this->cache->set($cacheKey, json_decode($response->getBody())->events, 3600);
|
||||||
}
|
}
|
||||||
|
|
||||||
$events = collect($events);
|
$events = collect($events);
|
||||||
|
|
Loading…
Reference in a new issue