Completed
Push — 2.1 ( 28b26f...4d9204 )
by Alexander
10:53
created

ZendDataCache::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 4
cp 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\caching;
9
10
/**
11
 * ZendDataCache provides Zend data caching in terms of an application component.
12
 *
13
 * To use this application component, the [Zend Data Cache PHP extension](http://www.zend.com/en/products/server/)
14
 * must be loaded.
15
 *
16
 * Application configuration example:
17
 *
18
 * ```php
19
 * return [
20
 *     'components' => [
21
 *         'cache' => [
22
 *             'class' => yii\caching\Cache::class,
23
 *             'handler' => [
24
 *                 'class' => yii\caching\ZendDataCache::class,
25
 *             ],
26
 *         ],
27
 *         // ...
28
 *     ],
29
 *     // ...
30
 * ];
31
 * ```
32
 *
33
 * See [[\Psr\SimpleCache\CacheInterface]] for common cache operations that ZendDataCache supports.
34
 *
35
 * For more details and usage information on Cache, see the [guide article on caching](guide:caching-overview).
36
 *
37
 * @author Qiang Xue <[email protected]>
38
 * @since 2.0
39
 */
40
class ZendDataCache extends SimpleCache
41
{
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function getValue($key)
46
    {
47
        $result = zend_shm_cache_fetch($key);
48
        return $result === null ? false : $result;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    protected function setValue($key, $value, $ttl)
55
    {
56
        return zend_shm_cache_store($key, $value, $ttl);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    protected function deleteValue($key)
63
    {
64
        return zend_shm_cache_delete($key);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function clear()
71
    {
72
        return zend_shm_cache_clear();
73
    }
74
}
75