aboutsummaryrefslogtreecommitdiff
path: root/class/cache.php
diff options
context:
space:
mode:
Diffstat (limited to 'class/cache.php')
-rw-r--r--class/cache.php74
1 files changed, 73 insertions, 1 deletions
diff --git a/class/cache.php b/class/cache.php
index 8005484..b64ab9d 100644
--- a/class/cache.php
+++ b/class/cache.php
@@ -2,11 +2,17 @@
class cache {
public $token = "";
+ public $bypassCache;
private $db;
+ private $dbnmr;
+ private $dbpagecache;
+ private $db2nd;
+
public function __construct($rconnect, $rdb){
$this->db = new Redis();
+ $this->bypassCache=false;
try {
$this->db->connect($rconnect);
@@ -23,6 +29,9 @@ class cache {
} catch (Exception $e) {
return $e->getMessage();
}
+ $this->dbnmr = $rdb;
+ $this->dbpagecache = PAGECACHE_DB;
+ $this->db2nd = SECOND_CACHE;
}
public function check(){
@@ -58,12 +67,75 @@ class cache {
return $this->db->delete($key);
}
+ public function setPageCache($key, $value, $ttl = 3600){
+ $this->db->select( $this->dbpagecache );
+ $this->db->set( $key, $value, $ttl );
+ $this->db->select( $this->dbnmr );
+ }
+
+ public function getPageCache($key){
+ $this->db->select( $this->dbpagecache );
+ $data = $this->db->get( $key );
+ $this->db->select( $this->dbnmr );
+ return $data;
+ }
+
+ public function existsPageCache($key){
+ $this->db->select( $this->dbpagecache );
+ $data = $this->exists( $key );
+ $this->db->select( $this->dbnmr );
+ return $data;
+ }
+
+ public function flushPageCache(){
+ $this->db->select( $this->dbpagecache );
+ $this->db->flushDB();
+ $this->db->select( $this->dbnmr );
+ }
+
public function flush($token = null){
+ $this->flushPageCache();
if ( is_null($token) )
return $this->db->flushDB();
else
return $this->db->delete($token);
}
-}
+ public function flushAll(){
+ $this->db->flushDB();
+ $this->flushPageCache();
+ $this->flush2();
+ }
+ public function set2($key, $value, $ttl = null){
+ $this->db->select( $this->db2nd );
+ $this->db->set($key, $value, $ttl);
+ $this->db->select( $this->dbnmr );
+ }
+
+ public function get2($key){
+ $this->db->select( $this->db2nd );
+ $data = $this->db->get($key);
+ $this->db->select( $this->dbnmr );
+ return $data;
+ }
+
+ public function exists2($key){
+ $this->db->select( $this->db2nd );
+ $data = $this->db->exists($key);
+ $this->db->select( $this->dbnmr );
+ return $data;
+ }
+
+ public function flush2($token = null){
+ $this->db->select( $this->db2nd );
+ if ( is_null($token) )
+ $data = $this->db->flushDB();
+ else
+ $data = $this->db->delete($token);
+
+ $this->db->select( $this->dbnmr );
+ $this->flushPageCache();
+ return $data;
+ }
+}