CacheFactory::newNullCache()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Onoi\Cache;
4
5
use Doctrine\Common\Cache\Cache as DoctrineCacheClient;
6
use Zend\Cache\Storage\StorageInterface;
7
use BagOStuff;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
class CacheFactory {
16
17
	/**
18
	 * @var CacheFactory
19
	 */
20
	private static $instance = null;
21
22
	/**
23
	 * @since 1.0
24
	 *
25
	 * @return CacheFactory
26
	 */
27 2
	public static function getInstance() {
28
29 2
		if ( self::$instance === null ) {
30 2
			self::$instance = new self();
31 2
		}
32
33 2
		return self::$instance;
34
	}
35
36
	/**
37
	 * @since 1.0
38
	 */
39 1
	public static function clear() {
40 1
		self::$instance = null;
41 1
	}
42
43
	/**
44
	 * @since 1.0
45
	 *
46
	 * @param BagOStuff $cache
47
	 *
48
	 * @return MediaWikiCache
49
	 */
50 2
	public function newMediaWikiCache( BagOStuff $cache ) {
51 2
		return new MediaWikiCache( $cache );
52
	}
53
54
	/**
55
	 * @since 1.0
56
	 *
57
	 * @param DoctrineCacheClient $cache
58
	 *
59
	 * @return DoctrineCache
60
	 */
61 2
	public function newDoctrineCache( DoctrineCacheClient $cache ) {
62 2
		return new DoctrineCache( $cache );
63
	}
64
65
	/**
66
	 * @since 1.1
67
	 *
68
	 * @param integer $cacheSize
69
	 *
70
	 * @return FixedInMemoryLruCache
71
	 */
72 3
	public function newFixedInMemoryLruCache( $cacheSize = 500 ) {
73 3
		return new FixedInMemoryLruCache( $cacheSize );
74
	}
75
76
	/**
77
	 * @since 1.0
78
	 *
79
	 * @deprecated since 1.1, use CacheFactory::newFixedInMemoryLruCache
80
	 */
81 2
	public function newFixedInMemoryCache( $cacheSize = 500 ) {
82 2
		return $this->newFixedInMemoryLruCache( $cacheSize );
83
	}
84
85
	/**
86
	 * @since 1.0
87
	 *
88
	 * @param Cache[] $caches
89
	 *
90
	 * @return CompositeCache
91
	 */
92 2
	public function newCompositeCache( array $caches ) {
93 2
		return new CompositeCache( $caches );
94
	}
95
96
	/**
97
	 * @since 1.1
98
	 *
99
	 * @return NullCache
100
	 */
101 1
	public function newNullCache() {
102 1
		return new NullCache();
103
	}
104
105
	/**
106
	 * @since 1.1
107
	 *
108
	 * @param StorageInterface $cache
109
	 *
110
	 * @return ZendCache
111
	 */
112 1
	public function newZendCache( StorageInterface $cache ) {
113 1
		return new ZendCache( $cache );
114
	}
115
116
}
117