1
|
|
|
<?php namespace Arcanedev\GeoIP; |
2
|
|
|
|
3
|
|
|
use Arcanedev\GeoIP\Contracts\GeoIPCache; |
4
|
|
|
use Illuminate\Contracts\Cache\Repository as Store; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class Cache |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\GeoIP |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class Cache implements GeoIPCache |
13
|
|
|
{ |
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
15
|
|
|
| Properties |
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
17
|
|
|
*/ |
18
|
|
|
/** @var \Illuminate\Contracts\Cache\Repository */ |
19
|
|
|
protected $store; |
20
|
|
|
|
21
|
|
|
/** @var array */ |
22
|
|
|
protected $tags = []; |
23
|
|
|
|
24
|
|
|
/** @var int */ |
25
|
|
|
protected $expires = 30; |
26
|
|
|
|
27
|
|
|
/* ------------------------------------------------------------------------------------------------ |
28
|
|
|
| Constructor |
29
|
|
|
| ------------------------------------------------------------------------------------------------ |
30
|
|
|
*/ |
31
|
|
|
/** |
32
|
|
|
* Cache constructor. |
33
|
|
|
* |
34
|
|
|
* @param \Illuminate\Contracts\Cache\Repository $store |
35
|
|
|
* @param array $tags |
36
|
|
|
* @param int $expires |
37
|
|
|
*/ |
38
|
18 |
|
public function __construct(Store $store, array $tags, $expires = 30) |
39
|
|
|
{ |
40
|
18 |
|
$this->store = $store; |
41
|
18 |
|
$this->tags = $tags; |
42
|
18 |
|
$this->expires = $expires; |
43
|
18 |
|
} |
44
|
|
|
|
45
|
|
|
/* ------------------------------------------------------------------------------------------------ |
46
|
|
|
| Getters & Setters |
47
|
|
|
| ------------------------------------------------------------------------------------------------ |
48
|
|
|
*/ |
49
|
|
|
/** |
50
|
|
|
* Get the store instance. |
51
|
|
|
* |
52
|
|
|
* @return \Illuminate\Contracts\Cache\Repository |
53
|
|
|
*/ |
54
|
6 |
|
private function store() |
55
|
|
|
{ |
56
|
6 |
|
return empty($this->tags) ? $this->store : $this->store->tags($this->tags); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/* ------------------------------------------------------------------------------------------------ |
60
|
|
|
| Main Functions |
61
|
|
|
| ------------------------------------------------------------------------------------------------ |
62
|
|
|
*/ |
63
|
|
|
/** |
64
|
|
|
* Get an item from the cache. |
65
|
|
|
* |
66
|
|
|
* @param string $key |
67
|
|
|
* |
68
|
|
|
* @return \Arcanedev\GeoIP\Location|null |
69
|
|
|
*/ |
70
|
6 |
|
public function get($key) |
71
|
|
|
{ |
72
|
6 |
|
return is_array($value = $this->store()->get($key)) ? new Location($value) : null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set an item in cache. |
77
|
|
|
* |
78
|
|
|
* @param string $key |
79
|
|
|
* @param array $location |
80
|
|
|
*/ |
81
|
6 |
|
public function set($key, array $location) |
82
|
|
|
{ |
83
|
6 |
|
$this->store()->put($key, $location, $this->expires); |
84
|
6 |
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Flush cache for tags. |
88
|
|
|
*/ |
89
|
1 |
|
public function flush() |
90
|
1 |
|
{ |
91
|
|
|
$this->store()->flush(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.