aboutsummaryrefslogtreecommitdiffstats
path: root/lib/memcache/factory.php
blob: 1926582aa5c548a79378a7500905570d2e37372c (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
<?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;

class Factory {
	/**
	 * get a cache instance, will return null if no backend is available
	 *
	 * @param bool $global
	 * @return \OC\Memcache\Cache
	 */
	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;
		}
	}

	/**
	 * check if there is a memcache backend available
	 *
	 * @return bool
	 */
	public function isAvailable() {
		return XCache::isAvailable() || APC::isAvailable() || Memcached::isAvailable();
	}
}