Blame view

sources/lib/private/memcache/xcache.php 1.77 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
  <?php
  /**
   * Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
31b7f2792   Kload   Upgrade to ownclo...
8
  namespace OC\Memcache;
03e52840d   Kload   Init
9

a293d369c   Kload   Update sources to...
10
11
12
13
  /**
   * See http://xcache.lighttpd.net/wiki/XcacheApi for provided constants and
   * functions etc.
   */
31b7f2792   Kload   Upgrade to ownclo...
14
  class XCache extends Cache {
03e52840d   Kload   Init
15
  	/**
a293d369c   Kload   Update sources to...
16
  	 * entries in XCache gets namespaced to prevent collisions between ownCloud instances and users
03e52840d   Kload   Init
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  	 */
  	protected function getNameSpace() {
  		return $this->prefix;
  	}
  
  	public function get($key) {
  		return xcache_get($this->getNamespace().$key);
  	}
  
  	public function set($key, $value, $ttl=0) {
  		if($ttl>0) {
  			return xcache_set($this->getNamespace().$key, $value, $ttl);
  		}else{
  			return xcache_set($this->getNamespace().$key, $value);
  		}
  	}
  
  	public function hasKey($key) {
  		return xcache_isset($this->getNamespace().$key);
  	}
  
  	public function remove($key) {
  		return xcache_unset($this->getNamespace().$key);
  	}
  
  	public function clear($prefix='') {
a293d369c   Kload   Update sources to...
43
44
45
46
47
48
  		if (function_exists('xcache_unset_by_prefix')) {
  			return xcache_unset_by_prefix($this->getNamespace().$prefix);
  		} else {
  			// Since we can not clear by prefix, we just clear the whole cache.
  			xcache_clear_cache(\XC_TYPE_VAR, 0);
  		}
03e52840d   Kload   Init
49
50
  		return true;
  	}
31b7f2792   Kload   Upgrade to ownclo...
51
52
53
54
  
  	static public function isAvailable(){
  		if (!extension_loaded('xcache')) {
  			return false;
a293d369c   Kload   Update sources to...
55
56
  		}
  		if (\OC::$CLI) {
31b7f2792   Kload   Upgrade to ownclo...
57
  			return false;
31b7f2792   Kload   Upgrade to ownclo...
58
  		}
a293d369c   Kload   Update sources to...
59
60
61
62
63
64
65
66
67
68
69
  		if (!function_exists('xcache_unset_by_prefix') && ini_get('xcache.admin.enable_auth')) {
  			// We do not want to use XCache if we can not clear it without
  			// using the administration function xcache_clear_cache()
  			// AND administration functions are password-protected.
  			return false;
  		}
  		$var_size = (int) ini_get('xcache.var_size');
  		if (!$var_size) {
  			return false;
  		}
  		return true;
31b7f2792   Kload   Upgrade to ownclo...
70
  	}
03e52840d   Kload   Init
71
  }