/** * Validates a cached item. * * Checks that items are either permanent or did not expire. */ protected function isValid($cache) { if (!isset($cache->data)) { return FALSE; } // Check expire time. $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Make sure that cache tags were not expired. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { $cache->valid = FALSE; } return $cache->valid; }
/** * Prepares a cached item. * * Checks that items are either permanent or did not expire, and returns data * as appropriate. * * @param object $cache * An item loaded from cache_get() or cache_get_multiple(). * @param bool $allow_invalid * If FALSE, the method returns FALSE if the cache item is not valid. * * @return mixed * The item with data as appropriate or FALSE if there is no * valid item to load. */ protected function prepareItem($cache, $allow_invalid) { if (!isset($cache->data)) { return FALSE; } // Check expire time. $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the item's tags. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { $cache->valid = FALSE; } if (!$allow_invalid && !$cache->valid) { return FALSE; } return $cache; }
/** * Prepares a cached item. * * Checks that items are either permanent or did not expire, and unserializes * data as appropriate. * * @param object $cache * An item loaded from cache_get() or cache_get_multiple(). * @param bool $allow_invalid * If FALSE, the method returns FALSE if the cache item is not valid. * * @return mixed|false * The item with data unserialized as appropriate and a property indicating * whether the item is valid, or FALSE if there is no valid item to load. */ protected function prepareItem($cache, $allow_invalid) { if (!isset($cache->data)) { return FALSE; } $cache->tags = $cache->tags ? explode(' ', $cache->tags) : array(); // Check expire time. $cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME; // Check if invalidateTags() has been called with any of the items's tags. if (!$this->checksumProvider->isValid($cache->checksum, $cache->tags)) { $cache->valid = FALSE; } if (!$allow_invalid && !$cache->valid) { return FALSE; } // Unserialize and return the cached data. if ($cache->serialized) { $cache->data = unserialize($cache->data); } return $cache; }