Permalink
Browse files

added: automatic compression support

  • Loading branch information...
1 parent ba42538 commit f9776b5ed85fe4bc8b3d5cfc81f4b8dc3c9333b8 @hasokeric hasokeric committed Apr 17, 2011
Showing with 40 additions and 16 deletions.
  1. +9 −4 config/memcached.php
  2. +9 −9 controllers/example_memcached.php
  3. +22 −3 libraries/memcached_library.php
View
@@ -22,10 +22,15 @@
// --------------------------------------------------------------------------
$memcached['config'] = array(
- 'prefix' => '', // Prefixes every key value (useful for multi environment setups)
- 'compression' => MEMCACHE_COMPRESSED, // Default: MEMCACHE_COMPRESSED Compression Method or FALSE
- 'expiration' => 3600, // Default content expiration value (in seconds)
- 'delete_expiration' => 0 // Default time between the delete command and the actual delete action occurs (in seconds)
+ 'prefix' => '', // Prefixes every key value (useful for multi environment setups)
+ 'compression' => MEMCACHE_COMPRESSED, // Default: MEMCACHE_COMPRESSED Compression Method or FALSE
+
+ // Not necessary if you already are using 'compression'
+ 'auto_compress_tresh' => FALSE, // Controls the minimum value length before attempting to compress automatically.
+ 'auto_compress_savings' => 0.2, // Specifies the minimum amount of savings to actually store the value compressed. The supplied value must be between 0 and 1.
+
+ 'expiration' => 3600, // Default content expiration value (in seconds)
+ 'delete_expiration' => 0 // Default time between the delete command and the actual delete action occurs (in seconds)
);
@@ -39,14 +39,14 @@ function test()
function stats()
{
- $this->load->library('memcached_library');
-
- echo $this->memcached_library->getversion();
- echo "<br/>";
-
- // We can use any of the following "reset, malloc, maps, cachedump, slabs, items, sizes"
- $p = $this->memcached_library->getstats("sizes");
-
- var_dump($p);
+ $this->load->library('memcached_library');
+
+ echo $this->memcached_library->getversion();
+ echo "<br/>";
+
+ // We can use any of the following "reset, malloc, maps, cachedump, slabs, items, sizes"
+ $p = $this->memcached_library->getstats("sizes");
+
+ var_dump($p);
}
}
@@ -11,6 +11,7 @@ class Memcached_library
public function __construct()
{
+
$this->ci =& get_instance();
// Lets try to load Memcache or Memcached Class
@@ -22,14 +23,20 @@ public function __construct()
// Which one should be loaded
if ($this->m == "Memcached") { $this->m = new Memcached(); }
- else { $this->m = new Memcache(); }
+ else { $this->m = new Memcache(); }
log_message('debug', "Memcached Library: Memcached Class Loaded");
$this->auto_connect();
+
+ // Set Automatic Compression Settings
+ if ($this->config['config']['auto_compress_tresh']) {
+ $this->setcompressthreshold($this->config['config']['auto_compress_tresh'], $this->config['config']['auto_compress_savings']);
+ }
+
}
else {
- log_message('debug', "Memcached Library: Failed to load Memcached or Memcache Class");
- }
+ log_message('debug', "Memcached Library: Failed to load Memcached or Memcache Class");
+ }
}
/*
@@ -240,6 +247,18 @@ public function getstats($type="items")
return $this->m->getStats($type);
}
+ /*
+ +-------------------------------------+
+ Name: setcompresstreshold
+ Purpose: Set When Automatic compression should kick-in
+ @param return TRUE/FALSE
+ +-------------------------------------+
+ */
+ public function setcompressthreshold($tresh, $savings=0.2)
+ {
+ return $this->m->setCompressThreshold($tresh, $savings=0.2);
+ }
+
/*
+-------------------------------------+
Name: key_name

0 comments on commit f9776b5

Please sign in to comment.