2011-03-03 04:38:17 +00:00
|
|
|
<?php
|
2012-05-02 08:51:15 +00:00
|
|
|
/**
|
|
|
|
|
* Object caching using WinCache.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Cache
|
|
|
|
|
*/
|
2011-03-03 04:38:17 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Wrapper for WinCache object caching functions; identical interface
|
|
|
|
|
* to the APC wrapper
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Cache
|
|
|
|
|
*/
|
|
|
|
|
class WinCacheBagOStuff extends BagOStuff {
|
2015-10-04 05:59:38 +00:00
|
|
|
protected function doGet( $key, $flags = 0 ) {
|
2011-03-03 04:38:17 +00:00
|
|
|
$val = wincache_ucache_get( $key );
|
|
|
|
|
if ( is_string( $val ) ) {
|
|
|
|
|
$val = unserialize( $val );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $val;
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-18 22:57:42 +00:00
|
|
|
public function set( $key, $value, $expire = 0, $flags = 0 ) {
|
2011-03-03 04:38:17 +00:00
|
|
|
$result = wincache_ucache_set( $key, serialize( $value ), $expire );
|
|
|
|
|
|
|
|
|
|
/* wincache_ucache_set returns an empty array on success if $value
|
2017-02-25 21:53:36 +00:00
|
|
|
* was an array, bool otherwise */
|
2016-02-17 09:09:32 +00:00
|
|
|
return ( is_array( $result ) && $result === [] ) || $result;
|
2011-03-03 04:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-27 01:14:33 +00:00
|
|
|
public function delete( $key ) {
|
2011-03-03 04:38:17 +00:00
|
|
|
wincache_ucache_delete( $key );
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-02-18 23:47:06 +00:00
|
|
|
|
2016-06-07 23:39:06 +00:00
|
|
|
public function merge( $key, callable $callback, $exptime = 0, $attempts = 10, $flags = 0 ) {
|
2016-09-15 11:50:25 +00:00
|
|
|
if ( wincache_lock( $key ) ) { // optimize with FIFO lock
|
|
|
|
|
$ok = $this->mergeViaLock( $key, $callback, $exptime, $attempts, $flags );
|
|
|
|
|
wincache_unlock( $key );
|
|
|
|
|
} else {
|
|
|
|
|
$ok = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $ok;
|
2015-02-18 23:47:06 +00:00
|
|
|
}
|
2011-03-03 04:38:17 +00:00
|
|
|
}
|