You are here

protected function DatabaseRawBackend::prepareItem in Supercache 2.0.x

Same name and namespace in other branches
  1. 8 src/Cache/DatabaseRawBackend.php \Drupal\supercache\Cache\DatabaseRawBackend::prepareItem()

Prepares a cached item.

Checks that items are either permanent or did not expire, and unserializes data as appropriate.

Parameters

object $cache: An item loaded from cache_get() or cache_get_multiple().

Return value

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.

1 call to DatabaseRawBackend::prepareItem()
DatabaseRawBackend::getMultiple in src/Cache/DatabaseRawBackend.php
Returns data from the persistent cache when given an array of cache IDs.

File

src/Cache/DatabaseRawBackend.php, line 120
Contains \Drupal\supercache\Cache\DatabaseRawBackend.

Class

DatabaseRawBackend
Defines a default cache implementation.

Namespace

Drupal\supercache\Cache

Code

protected function prepareItem($cache) {

  // Check expire time.
  $valid = $cache->expire == CacheRawBackendInterface::CACHE_PERMANENT || $cache->expire >= $this->requestTime;
  if (!$valid) {
    return FALSE;
  }

  // Retrieve the proper data...
  switch ($cache->storage) {
    case 0:
      if ($cache->data_serialized === NULL) {
        return FALSE;
      }
      $cache->data = unserialize($cache->data_serialized);
      break;
    case 1:

      // Strings can actuallyl be NULL so nothing to check.
      $cache->data = $cache->data_string;
      break;
    case 2:
      if ($cache->data_int === NULL) {
        return FALSE;
      }
      $cache->data = (int) $cache->data_int;
      break;
    case 3:
      if ($cache->data_float === NULL) {
        return FALSE;
      }
      $cache->data = (double) $cache->data_float;
      break;
    default:
      throw new \Exception("Storage type  not supported. Somethign went wrong.");
  }

  // Remove storage
  unset($cache->data_serialized);
  unset($cache->data_string);
  unset($cache->data_int);
  unset($cache->data_float);
  unset($cache->storage);
  unset($cache->expire);
  return $cache;
}