Skip to content

Commit 31bc54d

Browse files
committed
Allow specifying cache prefix
1 parent 4a7e53b commit 31bc54d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

config/geoip.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@
137137

138138
'cache_expires' => 30,
139139

140+
/*
141+
|--------------------------------------------------------------------------
142+
| Cache Prefix
143+
|--------------------------------------------------------------------------
144+
|
145+
| Prefix used for cache keys (in addition to globally configured prefix).
146+
|
147+
*/
148+
149+
'cache_prefix' => 'geoip:',
150+
140151
/*
141152
|--------------------------------------------------------------------------
142153
| Default Location

src/Cache.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Cache
2020
*/
2121
protected $expires;
2222

23+
/** Cache prefix */
24+
protected string $prefix = '';
25+
2326
/**
2427
* Create a new cache instance.
2528
*
@@ -31,6 +34,13 @@ public function __construct(CacheManager $cache, $tags, $expires = 30)
3134
{
3235
$this->cache = $tags ? $cache->tags($tags) : $cache;
3336
$this->expires = $expires;
37+
38+
}
39+
40+
/** @internal */
41+
public function setPrefix(?string $prefix = null)
42+
{
43+
$this->prefix = (string) $prefix;
3444
}
3545

3646
/**
@@ -42,7 +52,7 @@ public function __construct(CacheManager $cache, $tags, $expires = 30)
4252
*/
4353
public function get($name)
4454
{
45-
$value = $this->cache->get($name);
55+
$value = $this->cache->get($this->prefix.$name);
4656

4757
return is_array($value)
4858
? new Location($value)
@@ -59,7 +69,7 @@ public function get($name)
5969
*/
6070
public function set($name, Location $location)
6171
{
62-
return $this->cache->put($name, $location->toArray(), $this->expires);
72+
return $this->cache->put($this->prefix.$name, $location->toArray(), $this->expires);
6373
}
6474

6575
/**

src/GeoIP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function __construct(array $config, CacheManager $cache)
9090
$this->config('cache_tags'),
9191
$this->config('cache_expires', 30)
9292
);
93+
$this->cache->setPrefix((string) $this->config('cache_prefix'));
9394

9495
// Set custom default location
9596
$this->default_location = array_merge(

0 commit comments

Comments
 (0)