You are here

class FieldEncryptDatabaseCache in Field Encryption 7

Class FieldEncryptDatabaseCache.

Hierarchy

Expanded class hierarchy of FieldEncryptDatabaseCache

3 string references to 'FieldEncryptDatabaseCache'
field_encrypt_enable in ./field_encrypt.install
Implements hook_enable().
field_encrypt_form_system_performance_settings_alter in ./field_encrypt.module
Implements hook_form_FORM_ID_alter().
field_encrypt_modules_disabled in ./field_encrypt.module
Implements hook_modules_disabled().

File

./field_encrypt.cache.inc, line 51
Field encryption cache classes.

View source
class FieldEncryptDatabaseCache extends DrupalDatabaseCache {
  use FieldEncyptCacheTrait;

  /**
   * Prepare a cached item.
   *
   * Checks that items are either permanent or did not expire, and unserializes
   * data as appropriate.
   *
   * @param object $cache
   *   An item loaded from cache_get() or cache_get_multiple().
   *
   * @return object
   *   The item with data unserialized as appropriate or FALSE if there is no
   *   valid item to load.
   */
  protected function prepareItem($cache) {
    global $user;
    if (!isset($cache->data)) {
      return FALSE;
    }

    // If enforcing a minimum cache lifetime, validate that the data is
    // currently valid for this user before we return it by making sure the
    // cache entry was created before the timestamp in the current session's
    // cache timer. The cache variable is loaded into the $user object by
    // _drupal_session_read() in session.inc. If the data is permanent or we're
    // not enforcing a minimum cache lifetime always return the cached data.
    if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && $user->cache > $cache->created) {

      // This cache data is too old and thus not valid for us, ignore it.
      return FALSE;
    }
    try {
      $cache->data = $this
        ->decrypt($cache->data);
    } catch (Exception $e) {
      watchdog_exception('field_encrypt', $e);
      return FALSE;
    }
    if ($cache->serialized) {
      $cache->data = unserialize($cache->data);
    }
    return $cache;
  }

  /**
   * {@inheritdoc}
   */
  public function set($cid, $data, $expire = CACHE_PERMANENT) {
    try {
      $encrypted_data = $this
        ->encrypt($data);
    } catch (Exception $e) {
      watchdog_exception('field_encrypt', $e);
      return;
    }
    $fields = array(
      'serialized' => !is_string($data),
      'created' => REQUEST_TIME,
      'expire' => $expire,
      'data' => $encrypted_data,
    );
    try {
      db_merge($this->bin)
        ->key(array(
        'cid' => $cid,
      ))
        ->fields($fields)
        ->execute();
    } catch (Exception $e) {

      // The database may not be available, so we'll ignore cache_set requests.
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDatabaseCache::$bin protected property
DrupalDatabaseCache::clear function Implements DrupalCacheInterface::clear(). Overrides DrupalCacheInterface::clear 1
DrupalDatabaseCache::garbageCollection protected function Garbage collection for get() and getMultiple().
DrupalDatabaseCache::get function Implements DrupalCacheInterface::get(). Overrides DrupalCacheInterface::get 1
DrupalDatabaseCache::getMultiple function Implements DrupalCacheInterface::getMultiple(). Overrides DrupalCacheInterface::getMultiple 1
DrupalDatabaseCache::isEmpty function Implements DrupalCacheInterface::isEmpty(). Overrides DrupalCacheInterface::isEmpty 1
DrupalDatabaseCache::isValidBin function Checks if $this->bin represents a valid cache table.
DrupalDatabaseCache::__construct function Constructs a DrupalDatabaseCache object.
FieldEncryptDatabaseCache::prepareItem protected function Prepare a cached item. Overrides DrupalDatabaseCache::prepareItem
FieldEncryptDatabaseCache::set public function Implements DrupalCacheInterface::set(). Overrides DrupalDatabaseCache::set
FieldEncyptCacheTrait::decrypt private function Decrypts the data from the Cache backend.
FieldEncyptCacheTrait::encrypt private function Encrypts the data for the Cache backend.