123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?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);
- }
- }
- ?>
|