Skip to content

Commit 9aad556

Browse files
committed
Refactor key prefixing to private method
1 parent 15ea028 commit 9aad556

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/Drivers/Cache.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ public function __construct(Store $store, string $prefix = 'rollout')
3737
$this->prefix = $prefix;
3838
}
3939

40+
/**
41+
* Prepends our key with the configured prefix.
42+
*
43+
* @param string $key
44+
* The key to prepend with the prefix.
45+
*
46+
* @return string
47+
* The prefixed key.
48+
*/
49+
private function prefixKey($key) : string
50+
{
51+
return sprintf('%s.%s', $this->prefix, $key);
52+
}
53+
4054
/**
4155
* Get's the value corresponding to the provided key from the cache. Note
4256
* this function has the side effect of prepending the local prefix to the
@@ -50,8 +64,7 @@ public function __construct(Store $store, string $prefix = 'rollout')
5064
*/
5165
public function get($key)
5266
{
53-
$key = sprintf('%s.%s', $this->prefix, $key);
54-
return $this->store->get($key, null);
67+
return $this->store->get($this->prefixKey($key), null);
5568
}
5669

5770
/**
@@ -67,8 +80,7 @@ public function get($key)
6780
*/
6881
public function set($key, $value)
6982
{
70-
$key = sprintf('%s.%s', $this->prefix, $key);
71-
$this->store->forever($key, $value);
83+
$this->store->forever($this->prefixKey($key), $value);
7284
}
7385

7486
/**
@@ -82,7 +94,6 @@ public function set($key, $value)
8294
*/
8395
public function remove($key)
8496
{
85-
$key = sprintf('%s.%s', $this->prefix, $key);
86-
$this->store->forget($key);
97+
$this->store->forget($this->prefixKey($key));
8798
}
8899
}

0 commit comments

Comments
 (0)