* Check if a key exists
*
* @param string $key
- * @param float $maxAge Ignore items older than this many seconds (since 1.32)
+ * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32)
* @return bool
*/
public function has( $key, $maxAge = 0.0 ) {
* If the item is already set, it will be pushed to the top of the cache.
*
* @param string $key
- * @return mixed Returns null if the key was not found
+ * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32)
+ * @return mixed Returns null if the key was not found or is older than $maxAge
*/
- public function get( $key ) {
- if ( !$this->has( $key ) ) {
+ public function get( $key, $maxAge = 0.0 ) {
+ if ( !$this->has( $key, $maxAge ) ) {
return null;
}
/**
* @param string|int $key
* @param string|int $field
- * @param float $maxAge
+ * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32)
* @return bool
*/
public function hasField( $key, $field, $maxAge = 0.0 ) {
return ( $maxAge <= 0 || $this->getAge( $key, $field ) <= $maxAge );
}
- public function getField( $key, $field ) {
- return $this->get( $key )[$field] ?? null;
+ /**
+ * @param string|int $key
+ * @param string|int $field
+ * @param float $maxAge Ignore items older than this many seconds [optional] (since 1.32)
+ * @return mixed Returns null if the key was not found or is older than $maxAge
+ */
+ public function getField( $key, $field, $maxAge = 0.0 ) {
+ if ( !$this->hasField( $key, $field, $maxAge ) ) {
+ return null;
+ }
+
+ return $this->cache[$key][$field];
}
/**
/**
* Clear one or several cache entries, or all cache entries
*
- * @param string|array $keys
+ * @param string|array|null $keys
* @return void
*/
public function clear( $keys = null ) {
- if ( $keys === null ) {
+ if ( func_num_args() == 0 ) {
$this->cache = [];
$this->timestamps = [];
} else {