30 lines
592 B
PHP
30 lines
592 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Cache;
|
|
|
|
use App\Cache\Repository\HashRedis;
|
|
use App\Helpers\JsonHelper;
|
|
use App\Support\IpAddress;
|
|
|
|
class IpAddressCache extends HashRedis
|
|
{
|
|
protected $name = 'ip-address';
|
|
|
|
public function getAddressInfo(string $ip)
|
|
{
|
|
$result = $this->get($ip);
|
|
|
|
if (!empty($result)) {
|
|
return JsonHelper::decode($result);
|
|
}
|
|
|
|
$result = di()->get(IpAddress::class)->get($ip);
|
|
if (!empty($result)) {
|
|
$this->add($ip, JsonHelper::encode($result));
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|