Permalink
Browse files

Add prefix functionality for Memcache keys

  • Loading branch information...
1 parent 1ba627d commit 1c6566e44eda0c351948361ad51af1085365580a @jeremylivingston jeremylivingston committed May 27, 2013
Showing with 14 additions and 0 deletions.
  1. +12 −0 Client/MemcacheClient.php
  2. +2 −0 Resources/config/services.yml
@@ -20,6 +20,7 @@ class MemcacheClient implements CacheClientInterface
protected $servers = array();
protected $sockttl = 0.2;
protected $compression = false;
+ protected $prefix = '';
/**
* Constructs the cache client using an injected Memcache instance
@@ -123,6 +124,7 @@ public function probeServer($ip, $port)
public function get($key)
{
if ($this->isSafe()) {
+ $key = $this->prefix . $key;
return $this->mem->get($key);
}
@@ -141,6 +143,7 @@ public function get($key)
public function set($key, $value, $ttl)
{
if ($this->isSafe()) {
+ $key = $this->prefix . $key;
return $this->mem->set($key, $value, $this->compression, $ttl);
}
@@ -157,6 +160,7 @@ public function set($key, $value, $ttl)
public function delete($key)
{
if ($this->isSafe()) {
+ $key = $this->prefix . $key;
return $this->mem->delete($key, 0);
}
@@ -185,4 +189,12 @@ public function getStats()
{
return $this->mem->getExtendedStats();
}
+
+ /**
+ * @param string $prefix
+ */
+ public function setPrefix($prefix)
+ {
+ $this->prefix = $prefix;
+ }
}
@@ -3,6 +3,7 @@ parameters:
beryllium_cache.client.class: Beryllium\CacheBundle\Client\MemcacheClient
beryllium_cache.client.memcache.class: Memcache
beryllium_cache.client.servers: { 127.0.0.1 : 11211 }
+ beryllium_cache.client.prefix: ''
services:
beryllium_cache.client.memcache:
@@ -12,6 +13,7 @@ services:
arguments: [@beryllium_cache.client.memcache]
calls:
- [ addServers, [ %beryllium_cache.client.servers% ] ]
+ - [ setPrefix, [ %beryllium_cache.client.prefix% ] ]
beryllium_cache:
class: %beryllium_cache.class%
calls:

0 comments on commit 1c6566e

Please sign in to comment.