Cache   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 8
dl 0
loc 27
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fetch() 0 6 2
A store() 0 6 2
A isAvailable() 0 3 2
1
<?php
2
3
/**
4
 * Wrapper class for key-value caching. Currently supports only APCu.
5
 */
6
class Cache
7
{
8
    /**
9
     * Wraps apc_fetch() & apcu_fetch()
10
     */
11
    public function fetch($key)
12
    {
13
        if (function_exists('apcu_fetch')) {
14
            return apcu_fetch($key);
15
        }
16
        return false;
17
    }
18
19
    /**
20
     * Wraps apc_store() and apcu_store()
21
     */
22
    public function store($key, $value, $ttl = 3600)
23
    {
24
        if (function_exists('apcu_store')) {
25
            return apcu_store($key, $value, $ttl);
26
        }
27
        return false;
28
    }
29
30
    public function isAvailable()
31
    {
32
        return (function_exists('apcu_store') && function_exists('apcu_fetch'));
33
    }
34
}
35