You are here

function varnish_flush_caches in Varnish 6

Same name and namespace in other branches
  1. 7 varnish.module \varnish_flush_caches()

Implementation of hook_flush_caches()

Flush caches on events like cron.

This borrows logic from cache_clear_all() to respect cache_lifetime.

File

./varnish.module, line 176
varnish.module Provide drupal hooks for integration with the Varnish control layer.

Code

function varnish_flush_caches() {
  if (variable_get('varnish_flush_cron', 0)) {
    if (variable_get('cache_lifetime', 0)) {
      $cache_flush = variable_get('cache_flush_varnish', 0);
      if ($cache_flush == 0) {

        // This is the first request to clear the cache, start a timer.
        variable_set('cache_flush_varnish', time());
      }
      elseif (time() > $cache_flush + variable_get('cache_lifetime', 0)) {
        varnish_purge_all_pages();
      }
    }
    else {
      varnish_purge_all_pages();
    }
  }
}