From: Brion Vibber Date: Mon, 22 Nov 2004 01:33:47 +0000 (+0000) Subject: Use compression in the objectcache table if zlib support is available. X-Git-Tag: 1.5.0alpha1~1282 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=b3ca6226ca1ab65ba8faa7a848bc8eae9c24c9df;p=lhc%2Fweb%2Fwiklou.git Use compression in the objectcache table if zlib support is available. Since we'll be using this for the parser cache when memcached is not set up, we'll want to actually put junk in there and saving space is nice. --- diff --git a/includes/ObjectCache.php b/includes/ObjectCache.php index 7e182d8d21..7689b9442b 100644 --- a/includes/ObjectCache.php +++ b/includes/ObjectCache.php @@ -232,7 +232,7 @@ class SqlBagOStuff extends BagOStuff { } if($row=$this->_fetchobject($res)) { $this->_debug("get: retrieved data; exp time is " . $row->exptime); - return unserialize($row->value); + return $this->_unserialize($row->value); } else { $this->_debug('get: no matching rows'); } @@ -252,7 +252,7 @@ class SqlBagOStuff extends BagOStuff { $this->delete( $key ); $this->_query( "INSERT INTO $0 (keyname,value,exptime) VALUES('$1','$2','$exp')", - $key, serialize($value)); + $key, $this->_serialize($value)); return true; /* ? */ } @@ -324,6 +324,38 @@ class SqlBagOStuff extends BagOStuff { /* Clear *all* items from cache table */ $this->_query( "DELETE FROM $0" ); } + + /** + * Serialize an object and, if possible, compress the representation. + * On typical message and page data, this can provide a 3X decrease + * in storage requirements. + * + * @param mixed $data + * @return string + */ + function _serialize( &$data ) { + $serial = serialize( $data ); + if( function_exists( 'gzdeflate' ) ) { + return gzdeflate( $serial ); + } else { + return $serial; + } + } + + /** + * Unserialize and, if necessary, decompress an object. + * @param string $serial + * @return mixed + */ + function &_unserialize( $serial ) { + if( function_exists( 'gzinflate' ) ) { + $decomp = @gzinflate( $serial ); + if( false !== $decomp ) { + $serial = $decomp; + } + } + return unserialize( $serial ); + } } /**