/var/www/(Del)gepgroup.hk/php-activerecord/lib/cache/Memcache.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace ActiveRecord;

class 
Memcache
{
    const 
DEFAULT_PORT 11211;

    private 
$memcache;

    
/**
     * Creates a Memcache instance.
     *
     * Takes an $options array w/ the following parameters:
     *
     * <ul>
     * <li><b>host:</b> host for the memcache server </li>
     * <li><b>port:</b> port for the memcache server </li>
     * </ul>
     * @param array $options
     */
    
public function __construct($options)
    {
        
$this->memcache = new \Memcache();
        
$options['port'] = isset($options['port']) ? $options['port'] : self::DEFAULT_PORT;

        if (!
$this->memcache->connect($options['host'],$options['port']))
            throw new 
CacheException("Could not connect to $options[host]:$options[port]");
    }

    public function 
flush()
    {
        
$this->memcache->flush();
    }

    public function 
read($key)
    {
        return 
$this->memcache->get($key);
    }

    public function 
write($key$value$expire)
    {
        
$this->memcache->set($key,$value,null,$expire);
    }
}
?>