1: <?php namespace Laravel\Cache\Drivers;
2:
3: class Memory extends Sectionable {
4:
5: 6: 7: 8: 9:
10: public $storage = array();
11:
12: 13: 14: 15: 16: 17:
18: public function has($key)
19: {
20: return ( ! is_null($this->get($key)));
21: }
22:
23: 24: 25: 26: 27: 28:
29: protected function retrieve($key)
30: {
31: if ($this->sectionable($key))
32: {
33: list($section, $key) = $this->parse($key);
34:
35: return $this->get_from_section($section, $key);
36: }
37: else
38: {
39: return array_get($this->storage, $key);
40: }
41: }
42:
43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: public function put($key, $value, $minutes)
57: {
58: if ($this->sectionable($key))
59: {
60: list($section, $key) = $this->parse($key);
61:
62: return $this->put_in_section($section, $key, $value, $minutes);
63: }
64: else
65: {
66: array_set($this->storage, $key, $value);
67: }
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: public function forever($key, $value)
78: {
79: if ($this->sectionable($key))
80: {
81: list($section, $key) = $this->parse($key);
82:
83: return $this->forever_in_section($section, $key, $value);
84: }
85: else
86: {
87: $this->put($key, $value, 0);
88: }
89: }
90:
91: 92: 93: 94: 95: 96:
97: public function forget($key)
98: {
99: if ($this->sectionable($key))
100: {
101: list($section, $key) = $this->parse($key);
102:
103: if ($key == '*')
104: {
105: $this->forget_section($section);
106: }
107: else
108: {
109: $this->forget_in_section($section, $key);
110: }
111: }
112: else
113: {
114: array_forget($this->storage, $key);
115: }
116: }
117:
118: 119: 120: 121: 122: 123:
124: public function forget_section($section)
125: {
126: array_forget($this->storage, 'section#'.$section);
127: }
128:
129: 130: 131: 132: 133:
134: public function flush()
135: {
136: $this->storage = array();
137: }
138:
139: 140: 141: 142: 143: 144: 145:
146: protected function section_item_key($section, $key)
147: {
148: return "section#{$section}.{$key}";
149: }
150:
151: }