1: <?php namespace Laravel\Cache\Drivers;
2:
3: abstract class Sectionable extends Driver {
4:
5: /**
6: * Indicates that section caching is implicit based on keys.
7: *
8: * @var bool
9: */
10: public $implicit = true;
11:
12: /**
13: * The implicit section key delimiter.
14: *
15: * @var string
16: */
17: public $delimiter = '::';
18:
19: /**
20: * Retrieve a sectioned item from the cache driver.
21: *
22: * @param string $section
23: * @param string $key
24: * @param mixed $default
25: * @return mixed
26: */
27: public function get_from_section($section, $key, $default = null)
28: {
29: return $this->get($this->section_item_key($section, $key), $default);
30: }
31:
32: /**
33: * Write a sectioned item to the cache.
34: *
35: * @param string $section
36: * @param string $key
37: * @param mixed $value
38: * @param int $minutes
39: * @return void
40: */
41: public function put_in_section($section, $key, $value, $minutes)
42: {
43: $this->put($this->section_item_key($section, $key), $value, $minutes);
44: }
45:
46: /**
47: * Write a sectioned item to the cache that lasts forever.
48: *
49: * @param string $section
50: * @param string $key
51: * @param mixed $value
52: * @return void
53: */
54: public function forever_in_section($section, $key, $value)
55: {
56: return $this->forever($this->section_item_key($section, $key), $value);
57: }
58:
59: /**
60: * Get a sectioned item from the cache, or cache and return the default value.
61: *
62: * @param string $section
63: * @param string $key
64: * @param mixed $default
65: * @param int $minutes
66: * @param string $function
67: * @return mixed
68: */
69: public function remember_in_section($section, $key, $default, $minutes, $function = 'put')
70: {
71: $key = $this->section_item_key($section, $key);
72:
73: return $this->remember($key, $default, $minutes, $function);
74: }
75:
76: /**
77: * Get a sectioned item from the cache, or cache the default value forever.
78: *
79: * @param string $section
80: * @param string $key
81: * @param mixed $default
82: * @return mixed
83: */
84: public function sear_in_section($section, $key, $default)
85: {
86: return $this->sear($this->section_item_key($section, $key), $default);
87: }
88:
89: /**
90: * Delete a sectioned item from the cache.
91: *
92: * @param string $section
93: * @param string $key
94: * @return void
95: */
96: public function forget_in_section($section, $key)
97: {
98: return $this->forget($this->section_item_key($section, $key));
99: }
100:
101: /**
102: * Delete an entire section from the cache.
103: *
104: * @param string $section
105: * @return int|bool
106: */
107: abstract public function forget_section($section);
108:
109: /**
110: * Indicates if a key is sectionable.
111: *
112: * @param string $key
113: * @return bool
114: */
115: protected function sectionable($key)
116: {
117: return $this->implicit and $this->sectioned($key);
118: }
119:
120: /**
121: * Determine if a key is sectioned.
122: *
123: * @param string $key
124: * @return bool
125: */
126: protected function sectioned($key)
127: {
128: return str_contains($key, '::');
129: }
130:
131: /**
132: * Get the section and key from a sectioned key.
133: *
134: * @param string $key
135: * @return array
136: */
137: protected function parse($key)
138: {
139: return explode('::', $key, 2);
140: }
141:
142: }