Completed
Push — master ( 630a63...988c90 )
by Henri
02:39
created

Cache::isAvailable()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 9.2
c 0
b 0
f 0
cc 4
eloc 2
nc 5
nop 0
1
<?php
2
3
/**
4
 * Wrapper class for key-value caching. Currently supports APC and APCu.
5
 */
6
class Cache 
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
9
    /**
10
     * Wraps apc_fetch() & apcu_fetch()
11
     */
12
    public function fetch($key) {
13
        if (function_exists('apc_fetch')) {
14
            return apc_fetch($key);
15
        }
16
        if (function_exists('apcu_fetch')) {
17
            return apcu_fetch($key);
18
        }
19
        return false;
20
    }
21
22
    /**
23
     * Wraps apc_store() and apcu_store()
24
     */
25
    public function store($key, $value, $ttl=3600) {
26
        if (function_exists('apc_store')) {
27
            return apc_store($key, $value);
28
        } 
29
        else if (function_exists('apcu_store')) {
30
            return apcu_store($key, $value, $ttl);
31
        }
32
    }
33
    
34
    public function isAvailable() {
35
        return ((function_exists('apc_store') && function_exists('apc_fetch')) || (function_exists('apcu_store') && function_exists('apcu_fetch')));
36
    }
37
}
38