You are here

function session_cache_get in Session Cache API 8

Same name and namespace in other branches
  1. 6 session_cache.module \session_cache_get()
  2. 7 session_cache.api.php \session_cache_get()
  3. 7 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 76
session_cache.module

Code

function session_cache_get($bin) {
  if (!isset($bin)) {
    return NULL;
  }
  $method = config('session_cache.settings')
    ->get('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}"]) ? unserialize($_COOKIE["Drupal_session_cache_{$bin}"]) : NULL;
    case SESSION_CACHE_STORAGE_DB_CORE:
      $sid = session_cache_get_sid();
      $cached = cache('session_cache')
        ->get("{$bin}:{$sid}");
      return is_object($cached) ? $cached->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);
  }
}