Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Removed local cache variable
Browse files Browse the repository at this point in the history
  • Loading branch information
BobNisco committed Jan 9, 2013
1 parent c682e04 commit 85b5151
Showing 1 changed file with 40 additions and 51 deletions.
91 changes: 40 additions & 51 deletions libraries/memcached_library.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Memcached_library
{

private $config;
private $local_cache = array();
private $m;
private $client_type;
private $ci;
protected $errors = array();



public function __construct()
{
$this->ci =& get_instance();

// Lets try to load Memcache or Memcached Class
$this->client_type = class_exists('Memcache') ? "Memcache" : (class_exists('Memcached') ? "Memcached" : FALSE);
if($this->client_type)

if($this->client_type)
{
$this->ci->load->config('memcached');
$this->config = $this->ci->config->item('memcached');

// Which one should be loaded
switch($this->client_type)
{
Expand All @@ -38,15 +36,15 @@ public function __construct()
break;
}
log_message('debug', "Memcached Library: $this->client_type Class Loaded");
$this->auto_connect();

$this->auto_connect();
}
else
{
log_message('error', "Memcached Library: Failed to load Memcached or Memcache Class");
}
}

/*
+-------------------------------------+
Name: auto_connect
Expand All @@ -70,11 +68,11 @@ private function auto_connect()
}
}
}

/*
+-------------------------------------+
Name: add_server
Purpose:
Purpose:
@param return : TRUE or FALSE
+-------------------------------------+
*/
Expand All @@ -83,7 +81,7 @@ public function add_server($server)
extract($server);
return $this->m->addServer($host, $port, $weight);
}

/*
+-------------------------------------+
Name: add
Expand All @@ -110,23 +108,22 @@ public function add($key = NULL, $value = NULL, $expiration = NULL)
}
else
{
$this->local_cache[$this->key_name($key)] = $value;
switch($this->client_type)
{
case 'Memcache':
$add_status = $this->m->add($this->key_name($key), $value, $this->config['config']['compression'], $expiration);
break;

default:
case 'Memcached':
$add_status = $this->m->add($this->key_name($key), $value, $expiration);
break;
}

return $add_status;
}
}

/*
+-------------------------------------+
Name: set
Expand All @@ -153,23 +150,22 @@ public function set($key = NULL, $value = NULL, $expiration = NULL)
}
else
{
$this->local_cache[$this->key_name($key)] = $value;
switch($this->client_type)
{
case 'Memcache':
$add_status = $this->m->set($this->key_name($key), $value, $this->config['config']['compression'], $expiration);
break;

default:
case 'Memcached':
$add_status = $this->m->set($this->key_name($key), $value, $expiration);
break;
}

return $add_status;
}
}

/*
+-------------------------------------+
Name: get
Expand All @@ -181,16 +177,12 @@ public function get($key = NULL)
{
if($this->m)
{
if(isset($this->local_cache[$this->key_name($key)]))
{
return $this->local_cache[$this->key_name($key)];
}
if(is_null($key))
{
$this->errors[] = 'The key value cannot be NULL';
return FALSE;
}

if(is_array($key))
{
foreach($key as $n=>$k)
Expand All @@ -204,10 +196,10 @@ public function get($key = NULL)
return $this->m->get($this->key_name($key));
}
}
return FALSE;
return FALSE;
}


/*
+-------------------------------------+
Name: delete
Expand All @@ -222,12 +214,12 @@ public function delete($key, $expiration = NULL)
$this->errors[] = 'The key value cannot be NULL';
return FALSE;
}

if(is_null($expiration))
{
$expiration = $this->config['config']['delete_expiration'];
}

if(is_array($key))
{
foreach($key as $multi)
Expand All @@ -237,11 +229,10 @@ public function delete($key, $expiration = NULL)
}
else
{
unset($this->local_cache[$this->key_name($key)]);
return $this->m->delete($this->key_name($key), $expiration);
}
}

/*
+-------------------------------------+
Name: replace
Expand All @@ -268,24 +259,22 @@ public function replace($key = NULL, $value = NULL, $expiration = NULL)
}
else
{
$this->local_cache[$this->key_name($key)] = $value;

switch($this->client_type)
{
case 'Memcache':
$replace_status = $this->m->replace($this->key_name($key), $value, $this->config['config']['compression'], $expiration);
break;

default:
case 'Memcached':
$replace_status = $this->m->replace($this->key_name($key), $value, $expiration);
break;
}

return $replace_status;
}
}

/*
+-------------------------------------+
Name: flush
Expand All @@ -297,19 +286,19 @@ public function flush()
{
return $this->m->flush();
}

/*
+-------------------------------------+
Name: getversion
Purpose: Get Server Vesion Number
@param Returns a string of server version number or FALSE on failure.
@param Returns a string of server version number or FALSE on failure.
+-------------------------------------+
*/
public function getversion()
{
return $this->m->getVersion();
}

/*
+-------------------------------------+
Name: getstats
Expand All @@ -325,15 +314,15 @@ public function getstats($type="items")
case 'Memcache':
$stats = $this->m->getStats($type);
break;

default:
case 'Memcached':
$stats = $this->m->getStats();
break;
}
return $stats;
}

/*
+-------------------------------------+
Name: setcompresstreshold
Expand All @@ -348,14 +337,14 @@ public function setcompressthreshold($tresh, $savings=0.2)
case 'Memcache':
$setcompressthreshold_status = $this->m->setCompressThreshold($tresh, $savings=0.2);
break;

default:
$setcompressthreshold_status = TRUE;
break;
}
return $setcompressthreshold_status;
}

/*
+-------------------------------------+
Name: key_name
Expand All @@ -367,9 +356,9 @@ private function key_name($key)
{
return md5(strtolower($this->config['config']['prefix'].$key));
}
}



}
/* End of file memcached_library.php */
/* Location: ./application/libraries/memcached_library.php */
/* Location: ./application/libraries/memcached_library.php */

0 comments on commit 85b5151

Please sign in to comment.