X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=inline;f=classes%2FMemcached_DataObject.php;h=f7cbb9d5b6c375b50f9c7dbc46b3a8eb2496e80b;hb=65ef1cb72a7d93dc2d031e0d9766ed1fb5c27edc;hp=b9f599dbc8edc0a6d6b4664502f6abf1bfd6916e;hpb=02877224b20f87af304553f739b69544d7ac4cfa;p=quix0rs-gnu-social.git diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index b9f599dbc8..f7cbb9d5b6 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -1,7 +1,7 @@ decache(); # while we still have the values! return parent::delete(); } - + static function memcache() { return common_memcache(); } - + static function cacheKey($cls, $k, $v) { return common_cache_key(strtolower($cls).':'.$k.':'.$v); } - + static function getcached($cls, $k, $v) { $c = Memcached_DataObject::memcache(); if (!$c) { @@ -114,7 +114,7 @@ class Memcached_DataObject extends DB_DataObject } return $_DB_DATAOBJECT['INI'][$this->_database][$this->__table."__keys"]; } - + function encache() { $c = $this->memcache(); @@ -122,7 +122,7 @@ class Memcached_DataObject extends DB_DataObject return false; } else { $pkey = array(); - $pval = array(); + $pval = array(); $types = $this->keyTypes(); ksort($types); foreach ($types as $key => $type) { @@ -139,7 +139,7 @@ class Memcached_DataObject extends DB_DataObject $c->set($this->cacheKey($this->tableName(), $pkeys, $pvals), $this); } } - + function decache() { $c = $this->memcache(); @@ -147,7 +147,7 @@ class Memcached_DataObject extends DB_DataObject return false; } else { $pkey = array(); - $pval = array(); + $pval = array(); $types = $this->keyTypes(); ksort($types); foreach ($types as $key => $type) { @@ -193,7 +193,14 @@ class Memcached_DataObject extends DB_DataObject // unable to connect to sphinx' search daemon if (!$connected) { if ('mysql' === common_config('db', 'type')) { - $search_engine = new MySQLSearch($this, $table); + $type = common_config('search', 'type'); + if ($type == 'like') { + $search_engine = new MySQLLikeSearch($this, $table); + } else if ($type == 'fulltext') { + $search_engine = new MySQLSearch($this, $table); + } else { + throw new ServerException('Unknown search type: ' . $type); + } } else { $search_engine = new PGSearch($this, $table); } @@ -201,4 +208,57 @@ class Memcached_DataObject extends DB_DataObject } return $search_engine; } + + static function cachedQuery($cls, $qry, $expiry=3600) + { + $c = Memcached_DataObject::memcache(); + if (!$c) { + $inst = new $cls(); + $inst->query($qry); + return $inst; + } + $key_part = common_keyize($cls).':'.md5($qry); + $ckey = common_cache_key($key_part); + $stored = $c->get($ckey); + if ($stored) { + return new ArrayWrapper($stored); + } + + $inst = new $cls(); + $inst->query($qry); + $cached = array(); + while ($inst->fetch()) { + $cached[] = clone($inst); + } + $inst->free(); + $c->set($ckey, $cached, MEMCACHE_COMPRESSED, $expiry); + return new ArrayWrapper($cached); + } + + // We overload so that 'SET NAMES "utf8"' is called for + // each connection + + function _connect() + { + global $_DB_DATAOBJECT; + $exists = !empty($this->_database_dsn_md5) && + isset($_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]); + $result = parent::_connect(); + if (!$exists) { + $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; + if (common_config('db', 'type') == 'mysql' && + common_config('db', 'utf8')) { + $conn = $DB->connection; + if (!empty($conn)) { + if ($DB instanceof DB_mysqli) { + mysqli_set_charset($conn, 'utf8'); + } else if ($DB instanceof DB_mysql) { + mysql_set_charset('utf8', $conn); + } + } + } + } + return $result; + } + }