You are here

function session_cache_file_session_cache_set in Session Cache API 8

Same name and namespace in other branches
  1. 7 session_cache_file/session_cache_file.module \session_cache_file_session_cache_set()

Implements hook_session_cache_set().

File

session_cache_file/session_cache_file.module, line 51
session_cache_file.module

Code

function session_cache_file_session_cache_set($method, $bin, $data) {
  if ($method != SESSION_CACHE_STORAGE_FILE) {
    return;
  }
  $path = session_cache_file_directory($bin);
  $sid = session_cache_get_sid();
  if ($data == NULL) {
    if (!$path || !$sid || !@unlink("{$path}/{$sid}")) {
      drupal_set_message(t('Session cache file for empty session state could not be deleted.', array(
        '%bin' => "{$bin}/{$sid}",
      )), 'warning', FALSE);
    }
  }
  elseif (!$path || !$sid || @file_put_contents("{$path}/{$sid}", serialize($data), FILE_EXISTS_REPLACE) === FALSE) {
    drupal_set_message(t('Session cache file for session state %bin could not be written.', array(
      '%bin' => "{$bin}/{$sid}",
    )), 'error', FALSE);
  }
}