1 | <?php |
||
2 | |||
3 | namespace Translation\Cache; |
||
4 | |||
5 | use Illuminate\Contracts\Cache\Store; |
||
6 | |||
7 | class SimpleRepository implements CacheRepositoryInterface |
||
8 | { |
||
9 | /** |
||
10 | * The cache store implementation. |
||
11 | * |
||
12 | * @var \Illuminate\Contracts\Cache\Store |
||
13 | */ |
||
14 | protected $store; |
||
15 | |||
16 | /** |
||
17 | * Create a new cache repository instance. |
||
18 | * |
||
19 | * @param \Illuminate\Contracts\Cache\Store $store |
||
20 | * @return void |
||
21 | */ |
||
22 | public function __construct(Store $store, $cacheTag) |
||
23 | { |
||
24 | $this->store = $store; |
||
25 | $this->cacheTag = $cacheTag; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Checks if an entry with the given key exists in the cache. |
||
30 | * |
||
31 | * @param string $locale |
||
32 | * @param string $group |
||
33 | * @param string $namespace |
||
34 | * @return boolean |
||
35 | */ |
||
36 | public function has($locale, $group, $namespace) |
||
37 | { |
||
38 | return !is_null($this->get($locale, $group, $namespace)); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get an item from the cache |
||
43 | * |
||
44 | * @param string $locale |
||
45 | * @param string $group |
||
46 | * @param string $namespace |
||
47 | * @return mixed |
||
48 | */ |
||
49 | public function get($locale, $group, $namespace) |
||
50 | { |
||
51 | $key = $this->getKey($locale, $group, $namespace); |
||
52 | return $this->store->get($key); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Put an item into the cache store |
||
57 | * |
||
58 | * @param string $locale |
||
59 | * @param string $group |
||
60 | * @param string $namespace |
||
61 | * @param mixed $content |
||
62 | * @param integer $minutes |
||
63 | * @return void |
||
64 | */ |
||
65 | public function put($locale, $group, $namespace, $content, $minutes) |
||
66 | { |
||
67 | $key = $this->getKey($locale, $group, $namespace); |
||
68 | $this->store->put($key, $content, $minutes); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Flush the cache for the given entries |
||
73 | * |
||
74 | * @param string $locale |
||
75 | * @param string $group |
||
76 | * @param string $namespace |
||
77 | * @return void |
||
78 | */ |
||
79 | public function flush($locale, $group, $namespace) |
||
80 | { |
||
81 | $this->flushAll(); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * Completely flush the cache |
||
86 | * |
||
87 | * @param string $locale |
||
88 | * @param string $group |
||
89 | * @param string $namespace |
||
90 | * @return void |
||
91 | */ |
||
92 | public function flushAll() |
||
93 | { |
||
94 | $this->store->flush(); |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * Returns a unique cache key. |
||
99 | * |
||
100 | * @param string $locale |
||
101 | * @param string $group |
||
102 | * @param string $namespace |
||
103 | * @return string |
||
104 | */ |
||
105 | protected function getKey($locale, $group, $namespace) |
||
106 | { |
||
107 | return md5("{$this->cacheTag}-{$locale}-{$group}-{$namespace}"); |
||
108 | } |
||
109 | |||
110 | } |
||
111 |