方法
__construct()
构造
abstract public function __construct (
string $key
)
禁止擅自初始化「CacheItemInterface」对象
该类实例只能使用「CacheItemPoolInterface」对象的 getItem() 方法来获取
setHit()
设置是否命中
abstract public function setHit (
bool $is_hit
) : $this
getExpires()
获取缓存项的过期时间戳
abstract public function getExpires () : int|null
checkHit()
根据设置判断缓存是否有效
abstract public function checkHit () : bool
getKey()
Returns the key for the current cache item.
abstract public function getKey () : string
返回值: | The key string for this cache item. |
The key is loaded by the Implementing Library, but should be available to
the higher level callers when needed.
get()
Retrieves the value of the item from the cache associated with this object’s key.
abstract public function get () : mixed
返回值: | The value corresponding to this cache item’s key, or null if not found. |
The value returned must be identical to the value originally stored by set().
If isHit() returns false, this method MUST return null. Note that null
is a legitimate cached value, so the isHit() method SHOULD be used to
differentiate between "null value was found" and "no value was found."
isHit()
Confirms if the cache item lookup resulted in a cache hit.
abstract public function isHit () : bool
返回值: | True if the request resulted in a cache hit. False otherwise. |
Note: This method MUST NOT have a race condition between calling isHit()
and calling get().
set()
Sets the value represented by this cache item.
abstract public function set (
mixed $value
) : static
参数: |
名称 |
说明 |
value |
The serializable value to be stored. |
|
返回值: | The invoked object.
|
The $value argument may be any item that can be serialized by PHP,
although the method of serialization is left up to the Implementing
Library.
expiresAt()
Sets the expiration time for this cache item.
abstract public function expiresAt (
\DateTimeInterface|null $expiration
) : static
参数: | If null is passed explicitly, a default value MAY be used. If none is set,
the value should be stored permanently or for as long as the
implementation allows. |
+———–+———————————————————————————————————————————————————————————————————————————-+ |
返回值: | The called object. |
expiresAfter()
Sets the expiration time for this cache item.
abstract public function expiresAfter (
int|\DateInterval|null $time
) : static
参数: | expired. An integer parameter is understood to be the time in seconds until
expiration. If null is passed explicitly, a default value MAY be used.
If none is set, the value should be stored permanently or for as long as the
implementation allows. |
+——-+———————————————————————————————————————————————————————————————————————————————————————————————————————————–+ |
返回值: | The called object. |