diff --git a/config/geoip.php b/config/geoip.php index e54231f..ee0086c 100644 --- a/config/geoip.php +++ b/config/geoip.php @@ -137,6 +137,17 @@ 'cache_expires' => 30, + /* + |-------------------------------------------------------------------------- + | Cache Prefix + |-------------------------------------------------------------------------- + | + | Prefix used for cache keys (in addition to globally configured prefix). + | + */ + + 'cache_prefix' => 'geoip:', + /* |-------------------------------------------------------------------------- | Default Location diff --git a/src/Cache.php b/src/Cache.php index 857d62a..695c85c 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -20,6 +20,9 @@ class Cache */ protected $expires; + /** Cache prefix */ + protected string $prefix = ''; + /** * Create a new cache instance. * @@ -31,6 +34,13 @@ public function __construct(CacheManager $cache, $tags, $expires = 30) { $this->cache = $tags ? $cache->tags($tags) : $cache; $this->expires = $expires; + + } + + /** @internal */ + public function setPrefix(?string $prefix = null) + { + $this->prefix = (string) $prefix; } /** @@ -42,7 +52,7 @@ public function __construct(CacheManager $cache, $tags, $expires = 30) */ public function get($name) { - $value = $this->cache->get($name); + $value = $this->cache->get($this->prefix.$name); return is_array($value) ? new Location($value) @@ -59,7 +69,7 @@ public function get($name) */ public function set($name, Location $location) { - return $this->cache->put($name, $location->toArray(), $this->expires); + return $this->cache->put($this->prefix.$name, $location->toArray(), $this->expires); } /** diff --git a/src/GeoIP.php b/src/GeoIP.php index 52e64e3..d5a9d08 100644 --- a/src/GeoIP.php +++ b/src/GeoIP.php @@ -90,6 +90,7 @@ public function __construct(array $config, CacheManager $cache) $this->config('cache_tags'), $this->config('cache_expires', 30) ); + $this->cache->setPrefix((string) $this->config('cache_prefix')); // Set custom default location $this->default_location = array_merge(