aboutsummaryrefslogtreecommitdiffstats
path: root/lib/memcache/cache.php
blob: 331c689f0659858689a4624caac77c5fb5e22e04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
 * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
 */

namespace OC\Memcache;

abstract class Cache {
	/**
	 * get a cache instance
	 *
	 * @param bool $global
	 * @return Cache
	 */
	static function create($global = false) {
		if (XCache::isAvailable()) {
			return new XCache($global);
		} elseif (APC::isAvailable()) {
			return new APC($global);
		} elseif (Memcached::isAvailable()) {
			return new Memcached($global);
		} else {
			return null;
		}
	}

	/**
	 * @param bool $global
	 */
	abstract public function __construct($global);

	/**
	 * @param string $key
	 * @return mixed
	 */
	abstract public function get($key);

	/**
	 * @param string $key
	 * @param mixed $value
	 * @param int $ttl
	 * @return mixed
	 */
	abstract public function set($key, $value, $ttl = 0);

	/**
	 * @param string $key
	 * @return mixed
	 */
	abstract public function hasKey($key);

	/**
	 * @param string $key
	 * @return mixed
	 */
	abstract public function remove($key);

	/**
	 * @param string $prefix
	 * @return mixed
	 */
	abstract public function clear($prefix = '');

	/**
	 * @return bool
	 */
	static public function isAvailable() {
		return XCache::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
	}
}