(bug 28752) XCache doesn't work in CLI mode
[lhc/web/wiklou.git] / includes / objectcache / XCacheBagOStuff.php
1 <?php
2
3 /**
4 * Wrapper for XCache object caching functions; identical interface
5 * to the APC wrapper
6 *
7 * @ingroup Cache
8 */
9 class XCacheBagOStuff extends BagOStuff {
10 /**
11 * Are we operating in CLI mode? Since xcache doesn't work then and they
12 * don't want to change that
13 * @see bug 28752
14 * @var bool
15 */
16 private $isCli = false;
17
18 public function __construct() {
19 $this->isCli = php_sapi_name() == 'cli';
20 }
21
22 /**
23 * Get a value from the XCache object cache
24 *
25 * @param $key String: cache key
26 * @return mixed
27 */
28 public function get( $key ) {
29 if( $this->isCli ) {
30 return false;
31 }
32 $val = xcache_get( $key );
33
34 if ( is_string( $val ) ) {
35 $val = unserialize( $val );
36 }
37
38 return $val;
39 }
40
41 /**
42 * Store a value in the XCache object cache
43 *
44 * @param $key String: cache key
45 * @param $value Mixed: object to store
46 * @param $expire Int: expiration time
47 * @return bool
48 */
49 public function set( $key, $value, $expire = 0 ) {
50 if( !$this->isCli ) {
51 xcache_set( $key, serialize( $value ), $expire );
52 }
53 return true;
54 }
55
56 /**
57 * Remove a value from the XCache object cache
58 *
59 * @param $key String: cache key
60 * @param $time Int: not used in this implementation
61 * @return bool
62 */
63 public function delete( $key, $time = 0 ) {
64 if( !$this->isCli ) {
65 xcache_unset( $key );
66 }
67 return true;
68 }
69 }
70