start of cache engines
This commit is contained in:
parent
f9dffb96cb
commit
5e75ad3cd4
@ -49,7 +49,7 @@ class ImgQuerylet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// }}}
|
// }}}
|
||||||
// {{{ dbengines
|
// {{{ db engines
|
||||||
class DBEngine {
|
class DBEngine {
|
||||||
var $name = null;
|
var $name = null;
|
||||||
var $auto_increment = null;
|
var $auto_increment = null;
|
||||||
@ -71,7 +71,43 @@ class PostgreSQL extends DBEngine {
|
|||||||
function init($db) {
|
function init($db) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//}}}
|
// }}}
|
||||||
|
// {{{ cache engines
|
||||||
|
interface CacheEngine {
|
||||||
|
var $db;
|
||||||
|
public function cache_get($key);
|
||||||
|
public function cache_set($key, $val, $time);
|
||||||
|
public function cache_delete($key);
|
||||||
|
}
|
||||||
|
class MemCache implements CacheEngine {
|
||||||
|
public function __construct(Database $db) {
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cache_get($key) {
|
||||||
|
assert(!is_null($key));
|
||||||
|
$val = $this->db->memcache->get($key);
|
||||||
|
if($val) {
|
||||||
|
$this->cache_hits++;
|
||||||
|
return $val;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$this->cache_misses++;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cache_set($key, $val, $time=0) {
|
||||||
|
assert(!is_null($key));
|
||||||
|
$this->db->memcache->set($key, $val, false, $time);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cache_delete($key) {
|
||||||
|
assert(!is_null($key));
|
||||||
|
$this->db->memcache->delete($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// }}}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A class for controlled database access
|
* A class for controlled database access
|
||||||
@ -81,6 +117,7 @@ class Database {
|
|||||||
var $extensions;
|
var $extensions;
|
||||||
var $cache_hits = 0, $cache_misses = 0;
|
var $cache_hits = 0, $cache_misses = 0;
|
||||||
var $engine = null;
|
var $engine = null;
|
||||||
|
var $cache = null;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a new database object using connection info
|
* Create a new database object using connection info
|
||||||
@ -92,6 +129,15 @@ class Database {
|
|||||||
$this->engine = new MySQL();
|
$this->engine = new MySQL();
|
||||||
$this->db = @NewADOConnection($database_dsn);
|
$this->db = @NewADOConnection($database_dsn);
|
||||||
$this->use_memcache = isset($memcache);
|
$this->use_memcache = isset($memcache);
|
||||||
|
|
||||||
|
if(isset($memcache)) {
|
||||||
|
$this->cache = new MemCache($this);
|
||||||
|
}
|
||||||
|
if(isset($cache)) {
|
||||||
|
//$matches = array();
|
||||||
|
//preg_match("#(memcache)://#", $cache, $matches);
|
||||||
|
}
|
||||||
|
|
||||||
if($this->db) {
|
if($this->db) {
|
||||||
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
|
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
|
||||||
$this->engine->init($this->db);
|
$this->engine->init($this->db);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user