1: <?php
2: 3: 4: 5: 6: 7:
8:
9: namespace Wei;
10:
11: 12: 13: 14: 15:
16: class Cache extends BaseCache
17: {
18: 19: 20: 21: 22:
23: protected $object;
24:
25: 26: 27: 28: 29:
30: protected $driver = 'apc';
31:
32: 33: 34: 35: 36:
37: public function __construct(array $options = array())
38: {
39: parent::__construct($options);
40:
41: if (!$this->object) {
42: $this->setDriver($this->driver);
43: }
44: }
45:
46: 47: 48: 49: 50: 51: 52:
53: public function setDriver($driver)
54: {
55: $class = $this->wei->getClass($driver);
56:
57: if (!class_exists($class)) {
58: throw new \InvalidArgumentException(sprintf('Cache driver class "%s" not found', $class));
59: }
60:
61: if (!is_subclass_of($class, 'Wei\BaseCache')) {
62: throw new \InvalidArgumentException(sprintf('Cache driver class "%s" must extend "Wei\BaseCache"', $class));
63: }
64:
65: $this->driver = $driver;
66: $this->object = $this->wei->get($driver);
67: return $this;
68: }
69:
70: 71: 72: 73: 74:
75: public function getDriver()
76: {
77: return $this->driver;
78: }
79:
80: 81: 82:
83: public function get($key, $expire = null, $fn = null)
84: {
85: $result = $this->object->get($key);
86: return $this->processGetResult($key, $result, $expire, $fn);
87: }
88:
89: 90: 91:
92: public function set($key, $value, $expire = 0)
93: {
94: return $this->object->set($key, $value, $expire);
95: }
96:
97: 98: 99:
100: public function remove($key)
101: {
102: return $this->object->remove($key);
103: }
104:
105: 106: 107:
108: public function exists($key)
109: {
110: return $this->object->exists($key);
111: }
112:
113: 114: 115:
116: public function add($key, $value, $expire = 0)
117: {
118: return $this->object->add($key, $value, $expire);
119: }
120:
121: 122: 123:
124: public function replace($key, $value, $expire = 0)
125: {
126: return $this->object->replace($key, $value, $expire);
127: }
128:
129: 130: 131:
132: public function incr($key, $offset = 1)
133: {
134: return $this->object->incr($key, $offset);
135: }
136:
137: 138: 139:
140: public function clear()
141: {
142: return $this->object->clear();
143: }
144: }
145: