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: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 
<?php
namespace Apptus\Util\Cache;

/**
 * An implementation of the StateCache interface that uses the Alternative PHP Cache (APC).
 *
 * For more information about APC, see the {@link http://php.net/manual/en/book.apc.php PHP APC documentation}.
 */
class ApcStateCache implements StateCache {
    /**
     * Test if APC is working correctly.
     *
     * @param string
     *              Key to test with.
     * @param string
     *              Value to test with.
     * @return boolean|string
     *              True on success, or a string with what went wrong on failure.
     */
    public static function testApc($key = 'apctest', $value = 'apctest') {
        if (!extension_loaded('apc')) {
            return 'APC extension is not loaded.';
        } elseif (ini_get('apc.enabled') != 1) {
            return 'APC extension is not enabled.';
        } elseif (php_sapi_name() === 'cli' && ini_get('apc.enable_cli') == 0) {
            return 'PHP is running in cli mode but apc.enable_cli is not enabled.';
        }
        apc_store($key, $value, 2);
        $test = apc_fetch($key);
        if ($test !== $value) {
            return 'APC test failed.';
        }
        return true;
    }

    public function add($key, $value, $expire) {
        return apc_add($key, $value, $expire);
    }

    public function delete($key) {
        return apc_delete($key);
    }

    public function get($key) {
        return apc_fetch($key);
    }

    public function getMulti($keys) {
        return apc_fetch($keys);
    }

    public function replace($key, $value, $expire) {
        apc_fetch($key, $exists);
        if ($exists) {
            return apc_store($key, $value, $expire);
        }
        return false;
    }

    public function set($key, $value, $expire) {
        return apc_store($key, $value, $expire);
    }

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