Delete expired cache entries
351143
static function gc()
    {
        $rcube = rcube::get_instance();
        $db    = $rcube->get_dbh();
        $now   = $db->now();

        $db->query("DELETE FROM " . $db->table_name('cache_messages', true)
              ." WHERE `expires` < $now");

        $db->query("DELETE FROM " . $db->table_name('cache_index', true)
              ." WHERE `expires` < $now");

        $db->query("DELETE FROM ".$db->table_name('cache_thread', true)
              ." WHERE `expires` < $now");
    }
1332475
def clean_expired_tokens(opts):
    '''
    
    '''
    loadauth = salt.auth.LoadAuth(opts)
    for tok in loadauth.list_tokens():
        token_data = loadauth.get_tok(tok)
        if 'expire' not in token_data or token_data.get('expire', 0) < time.time():
            loadauth.rm_token(tok)
922971
def cleanup(self):
        """"""
        expires = maybe_timedelta(self.expires)
        for model in self.TaskModel, self.TaskSetModel:
            model._default_manager.delete_expired(expires)
790078
private void sanitizeDiskCache() {
        File[] cachedFiles = new File(diskCacheDirectory).listFiles();
        if (cachedFiles == null) {
            return;
        }
        for (File f : cachedFiles) {
        	// if file older than expirationInMinutes, remove it
        	long lastModified = f.lastModified();
        	Date now = new Date();
        	long ageInMinutes = ((now.getTime() - lastModified) / (1000*60));
        	
        	if (ageInMinutes >= expirationInMinutes) {
        		Log.d(name, "DISK cache expiration for file " + f.toString());
        		f.delete();
        	}
        }
	}
76469
public function deleteExpired()
    {
        $expired = Carbon::now()->subSeconds($this->expires);

        $this->makeDelete()
                ->where('o.createdAt < :expired')
                ->setParameter('expired', $expired)
                ->getQuery()
                ->execute();
    }
1125469
public function clearExpired()
    {
        if (! $this->enabled) {
            return;
        }
        $error = false;

        set_error_handler(function () use (&$error) {
            $error = true;
        }, E_WARNING);
        foreach (glob($this->getPath() . '/*.dat') as $file) {
            if (filemtime($file) < time()) {
                unlink($file);
            }
        }
        restore_error_handler();

        return ! $error;
    }
573477
def cleanup(self):
        
        now = time.time()
        expired = now - NODE_TIMEOUT
        if self.conn.zremrangebyscore(self.key, 0, expired):
            self._notify()
1341052
public function destroyExpiredCache()
    {
        $cacheData = $this->getCache();

        if (true === is_array($cacheData)) {
            $counter = 0;
            foreach ($cacheData as $key => $entry) {
                if (true === $this->isExpired($entry['time'], $entry['expire'])) {
                    unset($cacheData[$key]);
                    $counter++;
                }
            }

            if ($counter > 0) {
                $cacheData = json_encode($cacheData);
                @file_put_contents($this->getDirectory(), $cacheData);
            }

            return $counter;
        }
    }
1350897
public function eraseExpired() {
    $cacheData = $this->_loadCache();
    if (true === is_array($cacheData)) {
      $counter = 0;
      foreach ($cacheData as $key => $entry) {
        if (true === $this->_checkExpired($entry['time'], $entry['expire'])) {
          unset($cacheData[$key]);
          $counter++;
        }
      }
      if ($counter > 0) {
        $cacheData = json_encode($cacheData);
        file_put_contents($this->getCacheDir(), $cacheData);
      }
      return $counter;
    }
  }
1208119
function purgeCacheIfNecessary () {
  // If max cache size has not been exceeded, do nothing
  if (cacheSizeInBytes <= maximumSizeInBytes) {
    return;
  }

  // Cache size has been exceeded, create list of images sorted by timeStamp
  // So we can purge the least recently used image
  function compare (a, b) {
    if (a.timeStamp > b.timeStamp) {
      return -1;
    }
    if (a.timeStamp < b.timeStamp) {
      return 1;
    }

    return 0;
  }
  cachedImages.sort(compare);

  // Remove images as necessary)
  while (cacheSizeInBytes > maximumSizeInBytes) {
    const lastCachedImage = cachedImages[cachedImages.length - 1];
    const imageId = lastCachedImage.imageId;

    removeImageLoadObject(imageId);

    triggerEvent(events, EVENTS.IMAGE_CACHE_PROMISE_REMOVED, { imageId });
  }

  const cacheInfo = getCacheInfo();

  triggerEvent(events, EVENTS.IMAGE_CACHE_FULL, cacheInfo);
}
814342
def clear_caches(self):
        """"""
        self.get_repository.cache_clear()
        self._get_repository.cache_clear()
        self.pool.clear_caches()
1295371
def purge_cache(self):
        
        if len(self._cache) > self.max_cache_size:
            items = sorted(self._cache.items(), key=lambda (k, v): v['expiry'])
            self._cache = {k: v for k, v in items[self.max_cache_size:]
                           if not self._expired(v)}
28172
@Override
    @Scheduled(fixedRate = REAP_INTERVAL)
    public void removeExpired() {
        final Set<String> reapable = sessions.entrySet().stream()
                .filter(e -> e.getValue().getExpires().isPresent())
                .filter(e -> e.getValue().getExpires().get().isBefore(now()))
                .map(Map.Entry::getKey).collect(toSet());
        reapable.forEach(key -> {
            final FedoraSession s = sessions.get(key);
            if (s != null) {
                try {
                    s.expire();
                } catch (final RepositoryRuntimeException e) {
                    LOGGER.error("Got exception rolling back expired session {}: {}", s, e.getMessage());
                }
            }
            sessions.remove(key);
        });
    }
464313
@Override
  public long clearOldEntries(long cacheExpirationMs) {
    long oldestRemainingEntryAgeMs = 0L;
    synchronized (mLock) {
      try {
        long now = mClock.now();
        Collection<DiskStorage.Entry> allEntries = mStorage.getEntries();
        final long cacheSizeBeforeClearance = mCacheStats.getSize();
        int itemsRemovedCount = 0;
        long itemsRemovedSize = 0L;
        for (DiskStorage.Entry entry : allEntries) {
          // entry age of zero is disallowed.
          long entryAgeMs = Math.max(1, Math.abs(now - entry.getTimestamp()));
          if (entryAgeMs >= cacheExpirationMs) {
            long entryRemovedSize = mStorage.remove(entry);
            mResourceIndex.remove(entry.getId());
            if (entryRemovedSize > 0) {
              itemsRemovedCount++;
              itemsRemovedSize += entryRemovedSize;
              SettableCacheEvent cacheEvent = SettableCacheEvent.obtain()
                  .setResourceId(entry.getId())
                  .setEvictionReason(CacheEventListener.EvictionReason.CONTENT_STALE)
                  .setItemSize(entryRemovedSize)
                  .setCacheSize(cacheSizeBeforeClearance - itemsRemovedSize);
              mCacheEventListener.onEviction(cacheEvent);
              cacheEvent.recycle();
            }
          } else {
            oldestRemainingEntryAgeMs = Math.max(oldestRemainingEntryAgeMs, entryAgeMs);
          }
        }
        mStorage.purgeUnexpectedResources();
        if (itemsRemovedCount > 0) {
          maybeUpdateFileCacheSize();
          mCacheStats.increment(-itemsRemovedSize, -itemsRemovedCount);
        }
      } catch (IOException ioe) {
        mCacheErrorLogger.logError(
            CacheErrorLogger.CacheErrorCategory.EVICTION,
            TAG,
            "clearOldEntries: " + ioe.getMessage(),
            ioe);
      }
    }
    return oldestRemainingEntryAgeMs;
  }
427627
def delete_cached_files(self, prefixes=[], suffixes=[]):
        
        for filename in listdir(self.cache_directory_path):
            delete = (
                any([filename.endswith(ext) for ext in suffixes]) or
                any([filename.startswith(pre) for pre in prefixes]))
            if delete:
                path = join(self.cache_directory_path, filename)
                logger.info("Deleting %s", path)
                remove(path)
873052
protected function flushValues()
	{
		// first, remove expired content from cache
		eaccelerator_gc();
		// now, remove leftover cache-keys
		$keys = eaccelerator_list_keys();
		foreach($keys as $key)
			$this->deleteValue(substr($key['name'], 1));
		return true;
	}
617153
public void clear() {
    ArrayList<Entry<K, V>> oldExclusives;
    ArrayList<Entry<K, V>> oldEntries;
    synchronized (this) {
      oldExclusives = mExclusiveEntries.clear();
      oldEntries = mCachedEntries.clear();
      makeOrphans(oldEntries);
    }
    maybeClose(oldEntries);
    maybeNotifyExclusiveEntryRemoval(oldExclusives);
    maybeUpdateCacheParams();
  }