diff --git a/Plugin.php b/Plugin.php index 7ffb01f..323bb70 100644 --- a/Plugin.php +++ b/Plugin.php @@ -105,7 +105,8 @@ public static function config(Typecho_Widget_Helper_Form $form) 'redis' => _t('Redis'), 'memcached' => _t('Memcached'), 'mysql' => _t('MySQL'), - 'sqlite' => _t('SQLite') + 'sqlite' => _t('SQLite'), + 'postgres' => _t('PostgreSQL') ); $t = new Typecho_Widget_Helper_Form_Element_Radio( 'cachetype', @@ -128,7 +129,7 @@ public static function config(Typecho_Widget_Helper_Form $form) null, '6379', _t('缓存服务端口'), - _t('默认端口 memcache: 11211, Redis: 6379, Mysql: 3306') + _t('默认端口 memcache: 11211, Redis: 6379, Mysql: 3306, PostgreSQL: 5432') ); $form->addInput($t); diff --git a/driver/postgres.class.php b/driver/postgres.class.php new file mode 100644 index 0000000..8752d03 --- /dev/null +++ b/driver/postgres.class.php @@ -0,0 +1,52 @@ +db = Typecho_Db::get(); + $dbname = $this->db->getPrefix() . 'metingcache'; + $this->install(); + $this->db->query($this->db->delete('table.metingcache')->where('time <= ?', time())); + } + public function install() + { + $sql = ' +CREATE TABLE IF NOT EXISTS "' . $this->db->getPrefix() . 'metingcache' . '" ( + "key" varchar(32) NOT NULL PRIMARY KEY, + "data" text, + "time" NUMERIC(20) DEFAULT NULL +);'; + $this->db->query($sql); + } + public function set($key, $value, $expire = 86400) + { + $this->db->query($this->db->insert('table.metingcache')->rows(array( + 'key' => md5($key), + 'data' => $value, + 'time' => time() + $expire + ))); + } + public function get($key) + { + $rs = $this->db->fetchRow($this->db->select('data')->from('table.metingcache')->where('key = ?', md5($key))); + if (count($rs) == 0) { + return false; + } else { + return $rs['data']; + } + } + public function flush() + { + return $this->db->query($this->db->delete('table.metingcache')); + } + public function check() + { + $number = uniqid(); + $this->set('check', $number, 60); + $cache = $this->get('check'); + if ($number != $cache) { + throw new Exception('Cache Test Fall!'); + } + } +}