memcache api, for anyone who wants it :3

git-svn-id: file:///home/shish/svn/shimmie2/branches/branch_2.2@935 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2008-07-25 12:44:16 +00:00
parent 9993370fc6
commit 2c4582f147

View File

@ -73,6 +73,7 @@ class Database {
var $extensions;
var $get_images = "SELECT images.*,UNIX_TIMESTAMP(posted) AS posted_timestamp FROM images ";
var $engine = null;
var $cache_hits = 0, $cache_misses = 0;
/*
* Create a new database object using connection info
@ -83,6 +84,7 @@ class Database {
require_once "config.php";
$this->engine = new MySQL();
$this->db = @NewADOConnection($database_dsn);
$this->use_memcache = isset($memcache);
if($this->db) {
$this->db->SetFetchMode(ADODB_FETCH_ASSOC);
$this->db->Execute("SET NAMES utf8"); // FIXME: mysql specific :|
@ -101,6 +103,10 @@ class Database {
";
exit;
}
if($this->use_memcache) {
$this->memcache = new Memcache;
$this->memcache->pconnect('localhost', 11211) or ($this->use_memcache = false);
}
}
else {
header("Location: install.php");
@ -108,6 +114,33 @@ class Database {
}
}
// memcache {{{
public function cache_get($key) {
if($this->use_memcache) {
$val = $this->memcache->get($key);
if($val) {
$this->cache_hits++;
return $val;
}
else {
$this->cache_misses++;
}
}
return false;
}
public function cache_set($key, $val, $time=0) {
if($this->use_memcache) {
$this->memcache->set($key, $val, false, $time);
}
}
public function cache_delete($key) {
if($this->use_memcache) {
$this->memcache->delete($key);
}
}
// }}}
// misc {{{
public function count_images($tags=array()) {
if(count($tags) == 0) {