You are here

function session_cache_get in Session Cache API 7

Same name in this branch
  1. 7 session_cache.api.php \session_cache_get()
  2. 7 session_cache.module \session_cache_get()
Same name and namespace in other branches
  1. 8 session_cache.module \session_cache_get()
  2. 6 session_cache.module \session_cache_get()

Read data from the user session, given its bin id.

Parameters

string $bin: unique id eg a string prefixed by the module name

File

./session_cache.module, line 96
session_cache.module

Code

function session_cache_get($bin) {
  if (!isset($bin)) {
    return NULL;
  }
  $method = variable_get('session_cache_storage_method', SESSION_CACHE_STORAGE_SESSION);
  switch ($method) {
    case SESSION_CACHE_STORAGE_COOKIE:

      // Note that in array indices '.' are converted to '_'
      return isset($_COOKIE["Drupal_session_cache_{$bin}"]) ? json_decode($_COOKIE["Drupal_session_cache_{$bin}"], TRUE) : NULL;
    case SESSION_CACHE_STORAGE_DB_CORE:
      $sid = session_cache_get_sid();
      $cache = cache_get("{$bin}:{$sid}", 'cache_session_cache');
      return is_object($cache) ? $cache->data : NULL;
    case SESSION_CACHE_STORAGE_SESSION:
      return isset($_SESSION) && isset($_SESSION[$bin]) ? $_SESSION[$bin] : NULL;
    default:
      return module_invoke_all('session_cache_get', $method, $bin);
  }
}