You are here

private function crumbs_Container_AbstractLazyDataCached::getCached in Crumbs, the Breadcrumbs suite 7.2

Load data from persistent cache, or calls $this->get() if not in cache.

Parameters

string $key:

Return value

mixed|false Any value except NULL.

Throws

Exception

1 call to crumbs_Container_AbstractLazyDataCached::getCached()
crumbs_Container_AbstractLazyDataCached::__get in lib/Container/AbstractLazyDataCached.php

File

lib/Container/AbstractLazyDataCached.php, line 66

Class

crumbs_Container_AbstractLazyDataCached

Code

private function getCached($key) {
  $cache = cache_get("crumbs:{$key}");
  if (isset($cache->data)) {

    // We do the serialization manually,
    // to prevent Drupal from intercepting exceptions.
    // However, from previous versions we might still have non-serialized data.
    return is_array($cache->data) ? $cache->data : unserialize($cache->data);
  }
  $data = $this
    ->get($key);
  if (!is_array($data)) {
    throw new Exception("Only arrays can be cached in crumbs_CachedLazyPluginInfo.");
  }
  cache_set("crumbs:{$key}", serialize($data));
  return $data;
}