You are here

protected function MobileToolsDatabaseCache::garbageCollection in Mobile Tools 7.3

Garbage collection for get() and getMultiple().

Parameters

$bin: The bin being requested.

2 calls to MobileToolsDatabaseCache::garbageCollection()
MobileToolsDatabaseCache::getMultiple in mobile_tools_cache/mobile_tools_cache.module
Implements DrupalCacheInterface::getMultiple().
MobileToolsDatabaseCache::isEmpty in mobile_tools_cache/mobile_tools_cache.module
Implements DrupalCacheInterface::isEmpty().

File

mobile_tools_cache/mobile_tools_cache.module, line 89
Main module for mobile_tools_cache

Class

MobileToolsDatabaseCache
Implements DrupalCacheInterface

Code

protected function garbageCollection() {
  $cache_lifetime = variable_get('cache_lifetime', 0);

  // Clean-up the per-user cache expiration session data, so that the session
  // handler can properly clean-up the session data for anonymous users.
  if (isset($_SESSION['cache_expiration'])) {
    $expire = REQUEST_TIME - $cache_lifetime;
    foreach ($_SESSION['cache_expiration'] as $bin => $timestamp) {
      if ($timestamp < $expire) {
        unset($_SESSION['cache_expiration'][$bin]);
      }
    }
    if (!$_SESSION['cache_expiration']) {
      unset($_SESSION['cache_expiration']);
    }
  }

  // Garbage collection of temporary items is only necessary when enforcing
  // a minimum cache lifetime.
  if (!$cache_lifetime) {
    return;
  }

  // When cache lifetime is in force, avoid running garbage collection too
  // often since this will remove temporary cache items indiscriminately.
  $cache_flush = variable_get('cache_flush_' . $this->bin, 0);
  if ($cache_flush && $cache_flush + $cache_lifetime <= REQUEST_TIME) {

    // Reset the variable immediately to prevent a meltdown in heavy load situations.
    variable_set('cache_flush_' . $this->bin, 0);

    // Time to flush old cache data
    db_delete($this->bin)
      ->condition('expire', CACHE_PERMANENT, '<>')
      ->condition('expire', $cache_flush, '<=')
      ->execute();
  }
}