Completed
Push — 2.1 ( c952e8...98ed49 )
by Carsten
10:00
created

WinCache::setValues()   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 2
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
 * WinCache provides Windows Cache caching in terms of an application component.
12
 *
13
 * To use this application component, the [WinCache PHP extension](http://www.iis.net/expand/wincacheforphp)
14
 * must be loaded. Also note that "wincache.ucenabled" should be set to "On" in your php.ini file.
15
 *
16
 * See [[Cache]] manual for common cache operations that are supported by WinCache.
17
 *
18
 * @author Qiang Xue <[email protected]>
19
 * @since 2.0
20
 */
21
class WinCache extends Cache
22
{
23
    /**
24
     * Checks whether a specified key exists in the cache.
25
     * This can be faster than getting the value from the cache if the data is big.
26
     * Note that this method does not check whether the dependency associated
27
     * with the cached data, if there is any, has changed. So a call to [[get]]
28
     * may return false while exists returns true.
29
     * @param mixed $key a key identifying the cached value. This can be a simple string or
30
     * a complex data structure consisting of factors representing the key.
31
     * @return boolean true if a value exists in cache, false if the value is not in the cache or expired.
32
     */
33
    public function exists($key)
34
    {
35
        $key = $this->buildKey($key);
36
37
        return wincache_ucache_exists($key);
38
    }
39
40
    /**
41
     * Retrieves a value from cache with a specified key.
42
     * This is the implementation of the method declared in the parent class.
43
     * @param string $key a unique key identifying the cached value
44
     * @return string|boolean the value stored in cache, false if the value is not in the cache or expired.
45
     */
46
    protected function getValue($key)
47
    {
48
        return wincache_ucache_get($key);
49
    }
50
51
    /**
52
     * Retrieves multiple values from cache with the specified keys.
53
     * @param array $keys a list of keys identifying the cached values
54
     * @return array a list of cached values indexed by the keys
55
     */
56
    protected function getValues($keys)
57
    {
58
        return wincache_ucache_get($keys);
59
    }
60
61
    /**
62
     * Stores a value identified by a key in cache.
63
     * This is the implementation of the method declared in the parent class.
64
     *
65
     * @param string $key the key identifying the value to be cached
66
     * @param string $value the value to be cached
67
     * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
68
     * @return boolean true if the value is successfully stored into cache, false otherwise
69
     */
70
    protected function setValue($key, $value, $duration)
71
    {
72
        return wincache_ucache_set($key, $value, $duration);
73
    }
74
75
    /**
76
     * Stores multiple key-value pairs in cache.
77
     * @param array $data array where key corresponds to cache key while value is the value stored
78
     * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire.
79
     * @return array array of failed keys
80
     */
81
    protected function setValues($data, $duration)
82
    {
83
        return wincache_ucache_set($data, null, $duration);
84
    }
85
86
    /**
87
     * Stores a value identified by a key into cache if the cache does not contain this key.
88
     * This is the implementation of the method declared in the parent class.
89
     *
90
     * @param string $key the key identifying the value to be cached
91
     * @param string $value the value to be cached
92
     * @param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
93
     * @return boolean true if the value is successfully stored into cache, false otherwise
94
     */
95
    protected function addValue($key, $value, $duration)
96
    {
97
        return wincache_ucache_add($key, $value, $duration);
98
    }
99
100
    /**
101
     * Adds multiple key-value pairs to cache.
102
     * The default implementation calls [[addValue()]] multiple times add values one by one. If the underlying cache
103
     * storage supports multiadd, this method should be overridden to exploit that feature.
104
     * @param array $data array where key corresponds to cache key while value is the value stored
105
     * @param integer $duration the number of seconds in which the cached values will expire. 0 means never expire.
106
     * @return array array of failed keys
107
     */
108
    protected function addValues($data, $duration)
109
    {
110
        return wincache_ucache_add($data, null, $duration);
111
    }
112
113
    /**
114
     * Deletes a value with the specified key from cache
115
     * This is the implementation of the method declared in the parent class.
116
     * @param string $key the key of the value to be deleted
117
     * @return boolean if no error happens during deletion
118
     */
119
    protected function deleteValue($key)
120
    {
121
        return wincache_ucache_delete($key);
122
    }
123
124
    /**
125
     * Deletes all values from cache.
126
     * This is the implementation of the method declared in the parent class.
127
     * @return boolean whether the flush operation was successful.
128
     */
129
    protected function flushValues()
130
    {
131
        return wincache_ucache_clear();
132
    }
133
}
134