1: <?php
2:
3: namespace Psr\Cache;
4:
5: /**
6: * CacheItemInterface defines an interface for interacting with objects inside a cache.
7: */
8: interface CacheItemInterface
9: {
10: /**
11: * Returns the key for the current cache item.
12: *
13: * The key is loaded by the Implementing Library, but should be available to
14: * the higher level callers when needed.
15: *
16: * The key string for this cache item.
17: *
18: * @return string
19: */
20: public function getKey();
21:
22: /**
23: * Retrieves the value of the item from the cache associated with this object's key.
24: *
25: * The value returned must be identical to the value originally stored by set().
26: *
27: * If isHit() returns false, this method MUST return null. Note that null
28: * is a legitimate cached value, so the isHit() method SHOULD be used to
29: * differentiate between "null value was found" and "no value was found."
30: *
31: * The value corresponding to this cache item's key, or null if not found.
32: *
33: * @return mixed
34: */
35: public function get();
36:
37: /**
38: * Confirms if the cache item lookup resulted in a cache hit.
39: *
40: * Note: This method MUST NOT have a race condition between calling isHit()
41: * and calling get().
42: *
43: * True if the request resulted in a cache hit. False otherwise.
44: *
45: * @return bool
46: */
47: public function isHit();
48:
49: /**
50: * Sets the value represented by this cache item.
51: *
52: * The $value argument may be any item that can be serialized by PHP,
53: * although the method of serialization is left up to the Implementing
54: * Library.
55: *
56: * The serializable value to be stored.
57: * The invoked object.
58: *
59: * @param mixed $value
60: *
61: * @return \static
62: */
63: public function set($value);
64:
65: /**
66: * Sets the expiration time for this cache item.
67: *
68: * The point in time after which the item MUST be considered expired.
69: * If null is passed explicitly, a default value MAY be used. If none is set,
70: * the value should be stored permanently or for as long as the
71: * implementation allows.
72: * The called object.
73: *
74: * @param \DateTimeInterface $expiration
75: *
76: * @return \static
77: */
78: public function expiresAt($expiration);
79:
80: /**
81: * Sets the expiration time for this cache item.
82: *
83: * The period of time from the present after which the item MUST be considered
84: * expired. An integer parameter is understood to be the time in seconds until
85: * expiration. If null is passed explicitly, a default value MAY be used.
86: * If none is set, the value should be stored permanently or for as long as the
87: * implementation allows.
88: * The called object.
89: *
90: * @param int|\DateInterval $time
91: *
92: * @return \static
93: */
94: public function expiresAfter($time);
95: }
96: