CacheKeyProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 57
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getSiteCacheKey() 0 3 1
A getPageLanguageCacheBlobKey() 0 3 1
A getPageCacheKey() 0 3 2
1
<?php
2
3
namespace SIL;
4
5
/**
6
 * @license GNU GPL v2+
7
 * @since 1.0
8
 *
9
 * @author mwjames
10
 */
11
class CacheKeyProvider {
12
13
	/**
14
	 * Update the version to force a recache for all items due to
15
	 * required changes
16
	 */
17
	const VERSION = '1.1';
18
19
	/**
20
	 * @var string|null
21
	 */
22
	private $cachePrefix = null;
23
24
	/**
25
	 * @since 1.0
26
	 *
27
	 * @param string $cachePrefix
28
	 */
29 4
	public function __construct( $cachePrefix ) {
30 4
		$this->cachePrefix = $cachePrefix;
31 4
	}
32
33
	/**
34
	 * @since 1.0
35
	 *
36
	 * @param string $key
37
	 *
38
	 * @return  string
39
	 */
40 3
	public function getSiteCacheKey( $key ) {
41 3
		return $this->cachePrefix . ':sil:site:' . md5( $key . self::VERSION );
42
	}
43
44
	/**
45
	 * @since 1.0
46
	 *
47
	 * @param string $key
48
	 *
49
	 * @return  string
50
	 */
51 1
	public function getPageLanguageCacheBlobKey( $key = '' ) {
52 1
		return $this->cachePrefix . ':sil:blob:' . md5( $key . self::VERSION );
53
	}
54
55
	/**
56
	 * @since 1.0
57
	 *
58
	 * @param string $key
59
	 * @param boolean $stable
60
	 *
61
	 * @return  string
62
	 */
63 3
	public function getPageCacheKey( $key, $stable = true ) {
64 3
		return $this->cachePrefix . ':sil:page:' . md5( $key . ( $stable ? '' : self::VERSION ) );
65
	}
66
67
}
68