Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 1 Rev 192
Línea 8... Línea 8...
8
 
8
 
9
 
9
 
Línea 10... Línea -...
10
class CacheImpl implements CacheInterface
-
 
Línea 11... Línea 10...
11
{
10
class CacheImpl implements CacheInterface
12
    
-
 
13
    private $memcache;
-
 
14
    
-
 
15
    
-
 
16
    /**
-
 
17
     * 
-
 
18
     * @var int
-
 
19
     */
-
 
20
    private $ttl;
-
 
21
    
-
 
22
    
-
 
23
    /**
-
 
24
     *
-
 
25
     * @var string
-
 
26
     */
-
 
27
    private $host;
-
 
28
    
-
 
29
    
-
 
30
    /**
-
 
31
     *
-
 
32
     * @var int
11
{
33
     */
12
    
34
    private $port;
13
    
35
 
14
    
36
    /**
15
    /**
-
 
16
     *
37
     *
17
     * @param Array $config
38
     * @param Array $config
18
     */
39
     */
19
    public function __construct($config)
-
 
20
    {
40
    public function __construct($config)
21
        /*
41
    {
22
         $this->ttl    = intval($config['leaderslinked.memcache.ttl'], 10);
42
        $this->ttl    = intval($config['leaderslinked.memcache.ttl'], 10);
23
         $this->host   = strval($config['leaderslinked.memcache.host']);
43
        $this->host   = strval($config['leaderslinked.memcache.host']);
24
         $this->port   = intval($config['leaderslinked.memcache.port'], 10);
44
        $this->port   = intval($config['leaderslinked.memcache.port'], 10);
25
         
45
 
26
         
46
        if(class_exists(\Memcached::class)) {
27
         if(class_exists(\Memcached::class)) {
47
            $this->memcache = new \Memcached();
28
         $this->memcached = new \Memcached();
-
 
29
         $this->memcached->addServer($this->host, $this->port);
-
 
30
         } else  if(class_exists(\Memcache::class)) {
48
            $this->memcache->addServer($this->host, $this->port);
31
         $this->memcached = new \Memcache();
Línea 49... Línea 32...
49
        } else  if(class_exists(\Memcache::class)) {
32
         $this->memcached->addserver($this->host, $this->port);
50
            $this->memcache = new \Memcache();
33
         }*/
51
            $this->memcache->addserver($this->host, $this->port);
34
        
52
        }
35
        
53
    }
36
    }
54
    
37
    
55
    /**
38
    /**
-
 
39
     *
-
 
40
     * @param string $key
-
 
41
     * @param mixed $value
-
 
42
     */
-
 
43
    public function setItem($key, $value)
56
     * 
44
    {
-
 
45
        $filename = $this->getFilename($key);
57
     * @param string $key
46
        if(file_exists($filename)) {
Línea 58... Línea 47...
58
     * @param mixed $value
47
            @unlink($filename);
59
     */
48
        }
60
    public function setItem($key, $value)
49
        
61
    {
50
        return file_put_contents($filename, serialize($value));
62
        return $this->memcache->add($key, $value, $this->ttl);
51
        
63
    }
52
    }
64
    
53
    
-
 
54
    /**
65
    /**
55
     *
-
 
56
     * @param string $key
-
 
57
     * @return boolean
-
 
58
     */
-
 
59
    public function touch($key)
-
 
60
    {
66
     * 
61
        
Línea 67... Línea 62...
67
     * @param string $key
62
        $filename = $this->getFilename($key);
68
     * @return boolean
63
        if(file_exists($filename)) {
69
     */
64
            return touch($filename);
70
    public function touch($key)
65
        } else {
71
    {
66
            return true;
72
        return $this->memcache->touch($key, $this->ttl);
67
        }
73
    }
68
    }
74
    
69
    
-
 
70
    
-
 
71
    /**
-
 
72
     *
-
 
73
     * @param string $key
-
 
74
     * @return boolean
75
    
75
     */
Línea -... Línea 76...
-
 
76
    public function removeItem($key)
-
 
77
    {
76
    /**
78
        $filename = $this->getFilename($key);
77
     *
79
        if(file_exists($filename)) {
78
     * @param string $key
80
            return unlink($filename);
79
     * @return boolean
81
        } else {
80
     */
82
            return true;
81
    public function removeItem($key)
83
        }
82
    {
84
    }
-
 
85
    
-
 
86
    
Línea 83... Línea -...
83
        return $this->memcache->delete($key);
-
 
84
    }
-
 
85
    
-
 
86
    
-
 
87
    
-
 
88
    /**
-
 
89
     *
87
    
Línea 90... Línea 88...
90
     * @param string $key
88
    
91
     * @return boolean
89
    
92
     */
90
    /**
93
    public function hasItem($key)
91
     *
94
    {
92
     * @param string $key
95
        
93
     * @return boolean
96
        $value = $this->memcache->get($key);
94
     */
97
        if($value === \Memcached::RES_NOTFOUND) {
-
 
98
            return false;
-
 
99
        } else {
95
    public function hasItem($key)
100
            return true;
96
    {
101
        }
97
        $filename = $this->getFilename($key);
102
    }
98
        return file_exists($filename);
103
    
99
        
104
    
100
    }
-
 
101
    
-
 
102
    
-
 
103
    /**
-
 
104
     *
-
 
105
     * @param string $key
-
 
106
     * @return mixed
-
 
107
     */
-
 
108
    public function getItem($key)
-
 
109
    {
-
 
110
        $filename = $this->getFilename($key);
-
 
111
        if(file_exists($filename)) {
-
 
112
            return unserialize(file_get_contents($filename));
-
 
113
        } else {
-
 
114
            return null;
-
 
115
        }
-
 
116
        
105
    /**
117
    }
Línea -... Línea 118...
-
 
118
    
106
     *
119
    /**
107
     * @param string $key
120
     *
108
     * @return mixed
121
     * @param string $key
109
     */
122
     * @return string
110
    public function getItem($key)
123
     */
111
    {
124
    private function getFilename($key)
112
 
125
    {
113
        
126
        $filepath = 'data' . DIRECTORY_SEPARATOR . 'cache';
114
        $value = $this->memcache->get($key);
-
 
115
        if($value === \Memcached::RES_NOTFOUND) {
127
        if(!file_exists($filepath)) {