Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added: automatic compression support

  • Loading branch information...
commit f9776b5ed85fe4bc8b3d5cfc81f4b8dc3c9333b8 1 parent ba42538
Haso Keric hasokeric authored
13 config/memcached.php
@@ -22,10 +22,15 @@
22 22 // --------------------------------------------------------------------------
23 23 $memcached['config'] = array(
24 24
25   - 'prefix' => '', // Prefixes every key value (useful for multi environment setups)
26   - 'compression' => MEMCACHE_COMPRESSED, // Default: MEMCACHE_COMPRESSED Compression Method or FALSE
27   - 'expiration' => 3600, // Default content expiration value (in seconds)
28   - 'delete_expiration' => 0 // Default time between the delete command and the actual delete action occurs (in seconds)
  25 + 'prefix' => '', // Prefixes every key value (useful for multi environment setups)
  26 + 'compression' => MEMCACHE_COMPRESSED, // Default: MEMCACHE_COMPRESSED Compression Method or FALSE
  27 +
  28 + // Not necessary if you already are using 'compression'
  29 + 'auto_compress_tresh' => FALSE, // Controls the minimum value length before attempting to compress automatically.
  30 + '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.
  31 +
  32 + 'expiration' => 3600, // Default content expiration value (in seconds)
  33 + 'delete_expiration' => 0 // Default time between the delete command and the actual delete action occurs (in seconds)
29 34
30 35 );
31 36
18 controllers/example_memcached.php
@@ -39,14 +39,14 @@ function test()
39 39
40 40 function stats()
41 41 {
42   - $this->load->library('memcached_library');
43   -
44   - echo $this->memcached_library->getversion();
45   - echo "<br/>";
46   -
47   - // We can use any of the following "reset, malloc, maps, cachedump, slabs, items, sizes"
48   - $p = $this->memcached_library->getstats("sizes");
49   -
50   - var_dump($p);
  42 + $this->load->library('memcached_library');
  43 +
  44 + echo $this->memcached_library->getversion();
  45 + echo "<br/>";
  46 +
  47 + // We can use any of the following "reset, malloc, maps, cachedump, slabs, items, sizes"
  48 + $p = $this->memcached_library->getstats("sizes");
  49 +
  50 + var_dump($p);
51 51 }
52 52 }
25 libraries/memcached_library.php
@@ -11,6 +11,7 @@ class Memcached_library
11 11
12 12 public function __construct()
13 13 {
  14 +
14 15 $this->ci =& get_instance();
15 16
16 17 // Lets try to load Memcache or Memcached Class
@@ -22,14 +23,20 @@ public function __construct()
22 23
23 24 // Which one should be loaded
24 25 if ($this->m == "Memcached") { $this->m = new Memcached(); }
25   - else { $this->m = new Memcache(); }
  26 + else { $this->m = new Memcache(); }
26 27
27 28 log_message('debug', "Memcached Library: Memcached Class Loaded");
28 29 $this->auto_connect();
  30 +
  31 + // Set Automatic Compression Settings
  32 + if ($this->config['config']['auto_compress_tresh']) {
  33 + $this->setcompressthreshold($this->config['config']['auto_compress_tresh'], $this->config['config']['auto_compress_savings']);
  34 + }
  35 +
29 36 }
30 37 else {
31   - log_message('debug', "Memcached Library: Failed to load Memcached or Memcache Class");
32   - }
  38 + log_message('debug', "Memcached Library: Failed to load Memcached or Memcache Class");
  39 + }
33 40 }
34 41
35 42 /*
@@ -242,6 +249,18 @@ public function getstats($type="items")
242 249
243 250 /*
244 251 +-------------------------------------+
  252 + Name: setcompresstreshold
  253 + Purpose: Set When Automatic compression should kick-in
  254 + @param return TRUE/FALSE
  255 + +-------------------------------------+
  256 + */
  257 + public function setcompressthreshold($tresh, $savings=0.2)
  258 + {
  259 + return $this->m->setCompressThreshold($tresh, $savings=0.2);
  260 + }
  261 +
  262 + /*
  263 + +-------------------------------------+
245 264 Name: key_name
246 265 Purpose: standardizes the key names for memcache instances
247 266 @param return : md5 key name

0 comments on commit f9776b5

Please sign in to comment.
Something went wrong with that request. Please try again.