function memcache_storage_wildcard_flush in Memcache Storage 7
Invalidates all cache which should be invalid because of wildcard flushes.
1 string reference to 'memcache_storage_wildcard_flush'
- memcache_storage_init in ./
memcache_storage.module - Implements hook_init().
File
- ./
memcache_storage.module, line 130 - Provides hook implementation for Memcache Storage module.
Code
function memcache_storage_wildcard_flush() {
// Get list of cache bins which are stored in memcached.
$cache_bins = _memcache_storage_memcached_cache_bins();
foreach ($cache_bins as $bin) {
// Get instance of MemcacheStorage from static cache.
$object = _cache_get_object($bin);
if (!$object instanceof MemcacheStorage) {
continue;
}
// Check if the current cache bin has not yet invalidated wildcards.
$wildcards = $object
->getWildcards();
if (empty($wildcards)) {
continue;
}
// Load a list of all cache ids stored in the cache bin.
$cache_ids = $object
->getCacheIDs();
// Check if each cache may match any wildcard, and mark it as "delete
// candidate" if it is true.
$delete_ids = array();
foreach ($wildcards as $wildcard => $flush_timestamp) {
foreach ($cache_ids as $cache_id => $cache_created) {
if ($cache_created <= $flush_timestamp) {
if (strpos($cache_id, $wildcard) === 0) {
$delete_ids[] = $cache_id;
}
}
}
}
// Clear all cache items which are now invalid.
if (!empty($delete_ids)) {
$object
->clear($delete_ids);
}
// No need to store the information about wildcards for this cache bin
// anymore - all invalid items have been deleted.
$object
->clear('memcache_storage_wildcards');
}
// Set a timestamp of the latest wildcards invalidation.
variable_set('memcache_storage_last_wildcards_flush', REQUEST_TIME);
}