Passed
Push — master ( 9aa048...898b5e )
by Mattia
04:05
created

UserNotFoundCache::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Cache;
6
7
use Cache;
8
use Log;
9
10
class UserNotFoundCache
11
{
12
    private const PREFIX = 'not_found_';
13
    private const TTL = 86400;
14
15
    /**
16
     * @param string $usernameOrUuid
17
     *
18
     * @return bool
19
     */
20
    public static function has(string $usernameOrUuid): bool
21
    {
22
        if (Cache::has(self::PREFIX.\md5($usernameOrUuid))) {
23
            Log::debug('User not found cache hit: '.$usernameOrUuid);
24
25
            return true;
26
        }
27
28
        return false;
29
    }
30
31
    /**
32
     * @param $usernameOrUuid
33
     *
34
     * @return bool
35
     */
36
    public static function add($usernameOrUuid): bool
37
    {
38
        return Cache::add(self::PREFIX.\md5($usernameOrUuid), 1, self::TTL);
39
    }
40
}
41