1: <?php
2: /**
3: * @filesource Kotchasan/Cache/CacheItem.php
4: *
5: * @copyright 2016 Goragod.com
6: * @license http://www.kotchasan.com/license/
7: *
8: * @see http://www.kotchasan.com/
9: */
10:
11: namespace Kotchasan\Cache;
12:
13: use Psr\Cache\CacheItemInterface;
14:
15: /**
16: * Cache Item.
17: *
18: * @author Goragod Wiriya <admin@goragod.com>
19: *
20: * @since 1.0
21: */
22: class CacheItem implements CacheItemInterface
23: {
24: /**
25: * @var bool
26: */
27: private $hit;
28: /**
29: * Cache Key.
30: *
31: * @var string
32: */
33: private $key;
34: /**
35: * Cache value.
36: *
37: * @var mixed
38: */
39: private $value;
40:
41: /**
42: * Class constructor.
43: *
44: * @param string $key Cache Key
45: */
46: public function __construct($key)
47: {
48: $this->key = $key;
49: $this->value = null;
50: $this->hit = false;
51: }
52:
53: /**
54: * กำหนดอายุของแคช (วินาที).
55: *
56: * @param int|\DateInterval $time
57: *
58: * @return \static
59: */
60: public function expiresAfter($time)
61: {
62: }
63:
64: /**
65: * กำหนดวันที่และเวลาหมดอายุของแคช.
66: *
67: * @param \DateTimeInterface $expiration
68: *
69: * @return \static
70: */
71: public function expiresAt($expiration)
72: {
73: }
74:
75: /**
76: * อ่านค่าของแคช.
77: *
78: * @return mixed
79: */
80: public function get()
81: {
82: return $this->value;
83: }
84:
85: /**
86: * อ่านค่าคีย์ของแคช.
87: *
88: * @return string
89: */
90: public function getKey()
91: {
92: return $this->key;
93: }
94:
95: /**
96: * ฟังก์ชั่นตรวจสอบว่ามีการกำหนดข้อมูลลงในแคชหรือไม่
97: * คืนค่า true ถ้ามีการใส่ value ในแคชแล้ว.
98: *
99: * @return bool
100: */
101: public function isHit()
102: {
103: return $this->hit;
104: }
105:
106: /**
107: * กำหนดค่า.
108: *
109: * @param mixed $value
110: *
111: * @return \static
112: */
113: public function set($value)
114: {
115: $this->value = $value;
116: $this->hit = true;
117:
118: return $this;
119: }
120: }
121: