Overview

Namespaces

  • Apptus
    • ESales
      • Connector
        • Report
        • Time
    • Util
      • Cache
  • PHP
  • Overview
  • Namespace
  • Class
  • Tree
 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: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 
<?php
namespace Apptus\Util\Cache;

/**
 * An implementation of the StateCache interface using memcached.
 *
 * Note that there are two different interfaces to memcached in PHP.<br />
 * This class is using {@link http://php.net/manual/en/book.memcache.php Memcache} (without the <b>d</b>).
 */
class MemcacheStateCache implements StateCache {
    /** @var \Memcache */
    private $memcache;

    /**
     * Construct a new MemcacheStateCache.
     *
     * @param \Memcache A Memcache object.
     */
    public function __construct(\Memcache $memcache) {
        $this->memcache = $memcache;
    }

    public function add($key, $value, $expire) {
        return $this->memcache->add($key, (string) $value, false, $expire);
    }

    public function delete($key) {
        /** @noinspection PhpVoidFunctionResultUsedInspection
         * Included IntelliJ stub does not match documentation. */
        return $this->memcache->delete($key, 0);
    }

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

    public function getMulti($keys) {
        return $this->memcache->get($keys);
    }

    public function replace($key, $value, $expire) {
        /** @noinspection PhpVoidFunctionResultUsedInspection
         * Included IntelliJ stub does not match documentation. */
        return $this->memcache->replace($key, $value, false, $expire);
    }

    public function set($key, $value, $expire) {
        return $this->memcache->set($key, $value, false, $expire);
    }

    public function setMulti($items, $expire) {
        $result = true;
        foreach ($items as $key => $value) {
            $r = $this->memcache->set($key, $value, false, $expire);
            $result = $result && $r; // Beware short-circuit
        }
        return $result;
    }
}
Apptus ESales Connector PHP API documentation generated by ApiGen