Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16769 | Rev 16985 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 16769 Rev 16785
Línea 4... Línea 4...
4
 
4
 
Línea 5... Línea 5...
5
namespace LeadersLinked\Cache;
5
namespace LeadersLinked\Cache;
6
 
6
 
-
 
7
class CacheImpl implements CacheInterface
7
class CacheImpl implements CacheInterface
8
{
-
 
9
    /**
-
 
10
     * 
8
{
11
     * @var \Memcached|\Memcache
Línea 9... Línea 12...
9
    
12
     */
Línea 30... Línea 33...
30
     * @var int
33
     * @var int
31
     */
34
     */
32
    private $port;
35
    private $port;
Línea -... Línea 36...
-
 
36
    
-
 
37
    
33
    
38
    
34
    
39
    
35
    /**
40
    /**
36
     *
41
     *
37
     * @param Array $config
42
     * @param Array $config
Línea 45... Línea 50...
45
        
50
        
46
        if(class_exists(\Memcached::class)) {
51
        if(class_exists(\Memcached::class)) {
47
            $this->memcached = new \Memcached();
52
            $this->memcached = new \Memcached();
48
            $this->memcached->addServer($this->host, $this->port);
53
            $this->memcached->addServer($this->host, $this->port);
49
        } else  if(class_exists(\Memcache::class)) {
54
        } else  if(class_exists(\Memcache::class)) {
50
            $this->memcache = new \Memcache();
55
            $this->memcached = new \Memcache();
51
            $this->memcache->addserver($this->host, $this->port);
56
            $this->memcached->addserver($this->host, $this->port);
Línea -... Línea 57...
-
 
57
        }
52
        }
58
 
Línea 53... Línea 59...
53
 
59
 
54
    }
60
    }
55
    
61
    
56
    /**
62
    /**
57
     * 
63
     * 
58
     * @param string $key
64
     * @param string $key
59
     * @param mixed $value
65
     * @param mixed $value
-
 
66
     */
60
     */
67
    public function setItem($key, $value)
-
 
68
    {
-
 
69
        if($this->memcached) {
-
 
70
            $this->memcached->add($key, $value, $this->ttl);
-
 
71
        } else {
61
    public function setItem($key, $value)
72
            $filename = $this->getFilename($key);
Línea 62... Línea 73...
62
    {
73
            return file_put_contents($filename, serialize($value));
63
        $this->memcached->add($key, $value, $this->ttl);
74
        }
64
    }
75
    }
65
    
76
    
66
    /**
77
    /**
67
     * 
78
     * 
68
     * @param string $key
79
     * @param string $key
-
 
80
     * @return boolean
69
     * @return boolean
81
     */
-
 
82
    public function touch($key)
-
 
83
    {
-
 
84
        if($this->memcached) {
-
 
85
            return $this->memcached->touch($key, $this->ttl);
-
 
86
        } else {
-
 
87
            $filename = $this->getFilename($key);
-
 
88
            if(file_exists($filename)) {
-
 
89
                return touch($filename);
70
     */
90
            } else {
Línea 71... Línea 91...
71
    public function touch($key)
91
                return true;
72
    {
92
            }
73
        return $this->memcached->touch($key, $this->ttl);
93
        }
74
    }
94
    }
75
    
95
    
76
    
96
    
77
    /**
97
    /**
-
 
98
     *
78
     *
99
     * @param string $key
-
 
100
     * @return boolean
-
 
101
     */
-
 
102
    public function removeItem($key)
-
 
103
    {
-
 
104
        if($this->memcached) {
-
 
105
            return $this->memcached->delete($key);
-
 
106
        } else {
-
 
107
            $filename = $this->getFilename($key);
79
     * @param string $key
108
            if(file_exists($filename)) {
Línea 80... Línea 109...
80
     * @return boolean
109
                return unlink($filename);
81
     */
110
            } else {
82
    public function removeItem($key)
111
                return true;
83
    {
112
            }
84
        return $this->memcached->delete($key);
113
        }
85
    }
114
    }   
86
    
115
    
-
 
116
    
-
 
117
    
87
    
118
    /**
88
    
119
     *
89
    /**
120
     * @param string $key
-
 
121
     * @return boolean
-
 
122
     */
-
 
123
    public function hasItem($key)
90
     *
124
    {
-
 
125
        if($this->memcached) {
91
     * @param string $key
126
        
92
     * @return boolean
127
            $value = $this->memcached->get($key);
-
 
128
            if($value === \Memcached::RES_NOTFOUND) {
93
     */
129
                return false;
Línea 94... Línea 130...
94
    public function hasItem($key)
130
            } else {
95
    {
131
                return empty($value) ? false : true;
96
        $value = $this->memcached->get($key);
132
            }
97
        if($value === \Memcached::RES_NOTFOUND) {
133
        } else {
98
            return false;
134
            $filename = $this->getFilename($key);
99
        } else {
135
            return file_exists($filename);
100
            return true;
136
        }
-
 
137
            
-
 
138
    }
101
        }
139
    
102
    }
140
    
103
    
141
    /**
-
 
142
     *
-
 
143
     * @param string $key
-
 
144
     * @return mixed
104
    
145
     */
-
 
146
    public function getItem($key)
-
 
147
    {
-
 
148
        if($this->memcached) {
-
 
149
        
105
    /**
150
            $value = $this->memcached->get($key);
-
 
151
            if($value === \Memcached::RES_NOTFOUND) {
-
 
152
                return false; 
-
 
153
            } else {
-
 
154
                return $value;
-
 
155
            }
-
 
156
        } else {
-
 
157
            $filename = $this->getFilename($key);
-
 
158
            if(file_exists($filename)) {
-
 
159
                return unserialize(file_get_contents($filename)); 
-
 
160
            } else {
-
 
161
                return null;
-
 
162
            }
-
 
163
            
-
 
164
            
-
 
165
        }
-
 
166
    }
106
     *
167
    
-
 
168
    /**
-
 
169
     * 
107
     * @param string $key
170
     * @param string $key
Línea 108... Línea 171...
108
     * @return mixed
171
     * @return string