Total Complexity | 9 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class TestCacheFlusher implements MemberCacheFlusher |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | public static $categories = [ |
||
14 | 'apples', |
||
15 | 'pears', |
||
16 | 'bananas', |
||
17 | ]; |
||
18 | |||
19 | /** |
||
20 | * @var CacheInterface |
||
21 | */ |
||
22 | public $cache; |
||
23 | |||
24 | /** |
||
25 | * TestCacheFlusher constructor. |
||
26 | * @param CacheInterface $cache |
||
27 | */ |
||
28 | public function __construct(CacheInterface $cache) |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Clear the cache for this instance only |
||
35 | * |
||
36 | * @param array $memberIDs A list of member IDs |
||
37 | */ |
||
38 | public function flushMemberCache($memberIDs = null) |
||
39 | { |
||
40 | if (!$this->cache) { |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | // Hard flush, e.g. flush=1 |
||
45 | if (!$memberIDs) { |
||
46 | $this->cache->clear(); |
||
47 | } |
||
48 | |||
49 | if ($memberIDs && is_array($memberIDs)) { |
||
50 | foreach (self::$categories as $category) { |
||
51 | foreach ($memberIDs as $memberID) { |
||
52 | $key = $this->generateCacheKey($category, $memberID); |
||
53 | $this->cache->delete($key); |
||
54 | } |
||
55 | } |
||
56 | } |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param $category |
||
61 | * @param $memberID |
||
62 | * @return string |
||
63 | */ |
||
64 | public function generateCacheKey($category, $memberID) |
||
67 | } |
||
68 | } |
||
69 |