I need memcache
for store specific configuration keys. I've integrate memcache
inside my Settings
class, this class is instatiated each time that a request is performed. Infact, in my own framework, all requests are shunt from index.php
. So:
index.php -> autoloader (new Settings, new Model, new Controller, etc...) -> logic
the Settings
class is like this:
include 'config.php'; //contains the `$config` array
class Settings
{
private $_config = array();
private static $_memcache = null;
function __construct()
{
self::$_memcache = new Memcache();
self::$_memcache->connect('localhost', 11211); //take in the php doc example
$this->_config = $config;
foreach($config as $item => $value)
{
self::$_memcache->add($item, $value);
}
}
public static function set($name, $value)
{
self::$_memcache->set($name, $value);
}
public static function get($name)
{
return self::$_memcache->get($name);
}
}
How you can see I use the method
add, in the doc I've read that return false when a key is already setted. The value to set in memcache are taken from my $config
array that is included by config.php
file.
I also have two method set
that should set a specific key, and get
that should return a key.
The problem's that each time that this script is executed I get true
when I var_dump(self::$_memcache->add($item, $value));
.
I use self
for use static method of settings. What am I doing wrong?