Skip to content

Commit bc33343

Browse files
committed
Initial implementation of the PCI
1 parent 35369c5 commit bc33343

2 files changed

Lines changed: 86 additions & 2 deletions

File tree

src/Cache.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace J0sh0nat0r\SimpleCache;
44

5+
use J0sh0nat0r\SimpleCache\Internal\PCI;
6+
57
/**
68
* The master cache class of SimpleCache
79
*
@@ -10,6 +12,18 @@
1012
*/
1113
class 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
{

src/Internal/PCI.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
}

0 commit comments

Comments
 (0)