File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace J0sh0nat0r \SimpleCache ;
44
5+ use J0sh0nat0r \SimpleCache \Internal \PCI ;
6+
57/**
68 * The master cache class of SimpleCache
79 *
1012 */
1113class Cache
1214{
15+ /**
16+ * Default storage time for cache items
17+ */
18+ const DEFAULT_TIME = 3600 ;
19+
20+
21+ /**
22+ * @var PCI Provides a property based cache interface
23+ */
24+ public $ items ;
25+
26+
1327 /**
1428 * @var IDriver
1529 */
@@ -19,9 +33,15 @@ class Cache
1933 */
2034 private $ loaded = [];
2135
36+ /**
37+ * Cache constructor.
38+ * @param IDriver $driver
39+ * @param null $driver_options
40+ */
2241 public function __construct (IDriver $ driver , $ driver_options = null )
2342 {
2443 $ this ->driver = new $ driver ($ driver_options );
44+ $ this ->items = new PCI ($ this );
2545 }
2646
2747 /**
@@ -33,7 +53,7 @@ public function __construct(IDriver $driver, $driver_options = null)
3353 * @return bool
3454 * @throws \Exception
3555 */
36- public function store ($ key , $ value = null , $ time = 3600 )
56+ public function store ($ key , $ value = null , $ time = self :: DEFAULT_TIME )
3757 {
3858 if (is_array ($ key )) {
3959 $ time = is_null ($ value ) ? $ time : $ value ;
@@ -83,7 +103,7 @@ public function forever($key, $value = null)
83103 *
84104 * @param $key
85105 * @param null $default
86- * @return array| mixed|null
106+ * @return mixed
87107 */
88108 public function get ($ key , $ default = null )
89109 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace J0sh0nat0r \SimpleCache \Internal ;
4+
5+ use J0sh0nat0r \SimpleCache \Cache ;
6+
7+
8+ /**
9+ * Property-Cache interface.
10+ *
11+ * Class PCI
12+ * @package J0sh0nat0r\SimpleCache\Internal
13+ */
14+ class PCI
15+ {
16+ /**
17+ * @var Cache
18+ */
19+ private $ cache ;
20+
21+ /**
22+ * OCI constructor.
23+ * @param Cache $cache
24+ */
25+ public function __construct (Cache $ cache )
26+ {
27+ $ this ->cache = $ cache ;
28+ }
29+
30+ /**
31+ * @param $name
32+ * @param $value
33+ */
34+ function __set ($ name , $ value )
35+ {
36+ $ this ->cache ->store ($ name , $ value );
37+ }
38+
39+ /**
40+ * @param $name
41+ * @return bool
42+ */
43+ function __isset ($ name )
44+ {
45+ return $ this ->cache ->has ($ name );
46+ }
47+
48+ /**
49+ * @param $name
50+ * @return mixed
51+ */
52+ function __get ($ name )
53+ {
54+ return $ this ->cache ->get ($ name );
55+ }
56+
57+ /**
58+ * @param $name
59+ */
60+ function __unset ($ name )
61+ {
62+ $ this ->cache ->remove ($ name );
63+ }
64+ }
You can’t perform that action at this time.
0 commit comments