Cache::fetch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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