Overview

Namespaces

  • None
  • PHP
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Wei Framework
  4:  *
  5:  * @copyright   Copyright (c) 2008-2013 Twin Huang
  6:  * @license     http://opensource.org/licenses/mit-license.php MIT License
  7:  */
  8: 
  9: namespace Wei;
 10: 
 11: /**
 12:  * A cache service that stored data in PHP array
 13:  *
 14:  * @author      Twin Huang <twinhuang@qq.com>
 15:  */
 16: class ArrayCache extends BaseCache
 17: {
 18:     /**
 19:      * The array to store cache items
 20:      *
 21:      * @var array
 22:      */
 23:     protected $data = array();
 24: 
 25:     /**
 26:      * {@inheritdoc}
 27:      */
 28:     public function get($key, $expire = null, $fn = null)
 29:     {
 30:         $oriKey = $key;
 31:         $key = $this->prefix . $key;
 32:         $result = array_key_exists($key, $this->data) ? $this->data[$key] : false;
 33:         return $this->processGetResult($oriKey, $result, $expire, $fn);
 34:     }
 35: 
 36:     /**
 37:      * {@inheritdoc}
 38:      */
 39:     public function set($key, $value, $expire = 0)
 40:     {
 41:         $this->data[$this->prefix . $key] = $value;
 42:         return true;
 43:     }
 44: 
 45:     /**
 46:      * {@inheritdoc}
 47:      */
 48:     public function remove($key)
 49:     {
 50:         if (isset($this->data[$this->prefix . $key])) {
 51:             unset($this->data[$this->prefix . $key]);
 52:             return true;
 53:         } else {
 54:             return false;
 55:         }
 56:     }
 57: 
 58:     /**
 59:      * {@inheritdoc}
 60:      */
 61:     public function exists($key)
 62:     {
 63:         return array_key_exists($this->prefix . $key, $this->data);
 64:     }
 65: 
 66:     /**
 67:      * {@inheritdoc}
 68:      */
 69:     public function add($key, $value, $expire = 0)
 70:     {
 71:         if ($this->exists($key)) {
 72:             return false;
 73:         } else {
 74:             return $this->set($key, $value);
 75:         }
 76:     }
 77: 
 78:     /**
 79:      * {@inheritdoc}
 80:      */
 81:     public function replace($key, $value, $expire = 0)
 82:     {
 83:         if (!$this->exists($key)) {
 84:             return false;
 85:         } else {
 86:             $this->data[$this->prefix . $key] = $value;
 87:             return true;
 88:         }
 89:     }
 90: 
 91:     /**
 92:      * {@inheritdoc}
 93:      */
 94:     public function incr($key, $offset = 1)
 95:     {
 96:         if ($this->exists($key)) {
 97:             return $this->data[$this->prefix . $key] += $offset;
 98:         } else {
 99:             return $this->data[$this->prefix . $key] = $offset;
100:         }
101:     }
102: 
103:     /**
104:      * {@inheritdoc}
105:      */
106:     public function clear()
107:     {
108:         $this->data = array();
109:         return true;
110:     }
111: }
112: 
Wei Framework API documentation generated by ApiGen