You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2009/02/17 12:56:55 UTC
svn commit: r744974 -
/incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
Author: chabotc
Date: Tue Feb 17 11:56:54 2009
New Revision: 744974
URL: http://svn.apache.org/viewvc?rev=744974&view=rev
Log:
SHINDIG-922 by Nagy Attila - Changes the per-instance connection to a static one connection per process connection
Modified:
incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
Modified: incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php
URL: http://svn.apache.org/viewvc/incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php?rev=744974&r1=744973&r2=744974&view=diff
==============================================================================
--- incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php (original)
+++ incubator/shindig/branches/1.0.x-incubating/php/src/common/sample/CacheMemcache.php Tue Feb 17 11:56:54 2009
@@ -25,7 +25,7 @@
* (in a single server setup file based caching is actually faster)
*/
class CacheMemcache extends Cache {
- private $connection = false;
+ private static $connection = false;
private $host;
private $port;
@@ -42,7 +42,7 @@
private function isLocked($key) {
$this->check();
- if ((@memcache_get($this->connection, $key . '.lock')) === false) {
+ if ((@memcache_get(self::$connection, $key . '.lock')) === false) {
return false;
}
return true;
@@ -52,13 +52,13 @@
$this->check();
// the interesting thing is that this could fail if the lock was created in the meantime..
// but we'll ignore that out of convenience
- @memcache_add($this->connection, $key . '.lock', '', 0, 5);
+ @memcache_add(self::$connection, $key . '.lock', '', 0, 2);
}
private function removeLock($key) {
$this->check();
// suppress all warnings, if some other process removed it that's ok too
- @memcache_delete($this->connection, $key . '.lock');
+ @memcache_delete(self::$connection, $key . '.lock');
}
private function waitForLock($key) {
@@ -80,13 +80,13 @@
// I prefer lazy initalization since the cache isn't used every request
// so this potentially saves a lot of overhead
private function connect() {
- if (! $this->connection = @memcache_pconnect($this->host, $this->port)) {
+ if (! self::$connection = @memcache_pconnect($this->host, $this->port)) {
throw new CacheException("Couldn't connect to memcache server");
}
}
private function check() {
- if (! $this->connection) {
+ if (! self::$connection) {
$this->connect();
}
}
@@ -97,7 +97,7 @@
// default to global cache time
$expiration = Config::Get('cache_time');
}
- if (($ret = @memcache_get($this->connection, $key)) === false) {
+ if (($ret = @memcache_get(self::$connection, $key)) === false) {
return false;
}
if (time() - $ret['time'] > $expiration) {
@@ -110,7 +110,7 @@
public function set($key, $value) {
$this->check();
// we store it with the cache_time default expiration so objects will atleast get cleaned eventually.
- if (@memcache_set($this->connection, $key, array('time' => time(),
+ if (@memcache_set(self::$connection, $key, array('time' => time(),
'data' => $value), false, Config::Get('cache_time')) == false) {
throw new CacheException("Couldn't store data in cache");
}
@@ -118,6 +118,6 @@
public function delete($key) {
$this->check();
- @memcache_delete($this->connection, $key);
+ @memcache_delete(self::$connection, $key);
}
}