/**
 * Quick memcache interaction helper has transaction support using \Sky\Memcache
 * Sample Usage:
 *      mem('myKey', $myValue); // srite my key/value pair to memcache
 *      echo mem('myKey');      // read the value stored in 'myKey' and echo it
 *      mem('myKey', null);     // delete myKey from memcache
 *
 * @param   mixed   $key        can be a string or an array of strings
 * @param   mixed   $value      if not set, will be a read, if null, delete, else set
 * @param   string  $duration   how long you want to store the value, ex: '10 minutes'
 * @return  mixed
 */
function mem($key, $value = '§k¥', $duration = null)
{
    if ($value == '§k¥') {
        return \Sky\Memcache::get($key);
    } else {
        if (!is_null($value)) {
            return \Sky\Memcache::set($key, $value, $duration);
        } else {
            return \Sky\Memcache::delete($key);
        }
    }
}
 /**
  * Caches the current state of the object
  */
 public function updateCache()
 {
     $this->_cached_time = date('c');
     \Sky\Memcache::set($this->getMemKey(), $this);
 }
Example #3
0
 /**
  * Commits this TransactionValue,
  * deletes key if this is a delete, sets it and deletes tmp key if it s a set
  */
 public function commit()
 {
     if ($this->isSetType()) {
         \Sky\Memcache::setMemValue($this->getKey(), $this->getValue(), $this->getDuration());
         \Sky\Memcache::deleteMemValue($this->getTmpKey());
     } else {
         \Sky\Memcache::deleteMemValue($this->getKey());
     }
 }
Example #4
0
 /**
  * Sets the temporary key and stores the tmp value in cache
  * @param   string  $key
  * @param   mixed   $value
  * @param   string  $duration
  */
 public function __construct($key, $value, $duration = null)
 {
     $this->key = $key;
     $this->duration = $duration;
     \Sky\Memcache::setMemValue($this->generateTmpKey(), $value);
 }