summaryrefslogtreecommitdiff
path: root/system/libraries/Cache.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/libraries/Cache.php')
-rw-r--r--system/libraries/Cache.php87
1 files changed, 83 insertions, 4 deletions
diff --git a/system/libraries/Cache.php b/system/libraries/Cache.php
index 2ed344fa..024c1888 100644
--- a/system/libraries/Cache.php
+++ b/system/libraries/Cache.php
@@ -52,7 +52,7 @@ class Cache_Core {
// Test the config group name
if (($config = Kohana::config('cache.'.$config)) === NULL)
- throw new Kohana_Exception('The :group: group is not defined in your configuration.', array(':group:' => $name));
+ throw new Cache_Exception('The :group: group is not defined in your configuration.', array(':group:' => $name));
}
if (is_array($config))
@@ -74,7 +74,7 @@ class Cache_Core {
// Load the driver
if ( ! Kohana::auto_load($driver))
- throw new Kohana_Exception('The :driver: driver for the :class: library could not be found',
+ throw new Cache_Exception('The :driver: driver for the :class: library could not be found',
array(':driver:' => $this->config['driver'], ':class:' => get_class($this)));
// Initialize the driver
@@ -82,7 +82,7 @@ class Cache_Core {
// Validate the driver
if ( ! ($this->driver instanceof Cache_Driver))
- throw new Kohana_Exception('The :driver: driver for the :library: library must implement the :interface: interface',
+ throw new Cache_Exception('The :driver: driver for the :library: library must implement the :interface: interface',
array(':driver:' => $this->config['driver'], ':library:' => get_class($this), ':interface:' => 'Cache_Driver'));
Kohana_Log::add('debug', 'Cache Library initialized');
@@ -103,6 +103,16 @@ class Cache_Core {
$key = array($key => $value);
}
+ if ($this->config['prefix'] !== NULL)
+ {
+ $key = $this->add_prefix($key);
+
+ if ($tags !== NULL)
+ {
+ $tags = $this->add_prefix($tags, FALSE);
+ }
+ }
+
return $this->driver->set($key, $tags, $lifetime);
}
@@ -119,6 +129,17 @@ class Cache_Core {
$single = TRUE;
}
+ if ($this->config['prefix'] !== NULL)
+ {
+ $keys = $this->add_prefix($keys, FALSE);
+
+ if ( ! $single)
+ {
+ return $this->strip_prefix($this->driver->get($keys, $single));
+ }
+
+ }
+
return $this->driver->get($keys, $single);
}
@@ -132,7 +153,15 @@ class Cache_Core {
$tags = array($tags);
}
- return $this->driver->get_tag($tags);
+ if ($this->config['prefix'] !== NULL)
+ {
+ $tags = $this->add_prefix($tags, FALSE);
+ return $this->strip_prefix($this->driver->get_tag($tags));
+ }
+ else
+ {
+ return $this->driver->get_tag($tags);
+ }
}
/**
@@ -145,6 +174,11 @@ class Cache_Core {
$keys = array($keys);
}
+ if ($this->config['prefix'] !== NULL)
+ {
+ $keys = $this->add_prefix($keys, FALSE);
+ }
+
return $this->driver->delete($keys);
}
@@ -158,6 +192,11 @@ class Cache_Core {
$tags = array($tags);
}
+ if ($this->config['prefix'] !== NULL)
+ {
+ $tags = $this->add_prefix($tags, FALSE);
+ }
+
return $this->driver->delete_tag($tags);
}
@@ -168,4 +207,44 @@ class Cache_Core {
{
return $this->driver->delete_all();
}
+
+ /**
+ * Add a prefix to keys or tags
+ */
+ protected function add_prefix($array, $to_key = TRUE)
+ {
+ $out = array();
+
+ foreach($array as $key => $value)
+ {
+ if ($to_key)
+ {
+ $out[$this->config['prefix'].$key] = $value;
+ }
+ else
+ {
+ $out[$key] = $this->config['prefix'].$value;
+ }
+ }
+
+ return $out;
+ }
+
+ /**
+ * Strip a prefix to keys or tags
+ */
+ protected function strip_prefix($array)
+ {
+ $out = array();
+
+ $start = strlen($this->config['prefix']);
+
+ foreach($array as $key => $value)
+ {
+ $out[substr($key, $start)] = $value;
+ }
+
+ return $out;
+ }
+
} // End Cache Library \ No newline at end of file