From 67e809a682f02c2db007719396808ec2101c38a3 Mon Sep 17 00:00:00 2001 From: Tim Steiner <tsteiner2@unl.edu> Date: Mon, 19 Sep 2011 17:01:39 +0000 Subject: [PATCH] [gh-221] Merging from testing into staging git-svn-id: file:///tmp/wdn_thm_drupal/branches/drupal-7.x/staging@1059 20a16fea-79d4-4915-8869-1ea9d5ebf173 --- .../unl/unl_varnish/unl_varnish.module | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sites/all/modules/unl/unl_varnish/unl_varnish.module b/sites/all/modules/unl/unl_varnish/unl_varnish.module index 27f4c098..0fe2f0d4 100644 --- a/sites/all/modules/unl/unl_varnish/unl_varnish.module +++ b/sites/all/modules/unl/unl_varnish/unl_varnish.module @@ -39,3 +39,32 @@ function unl_varnish_purge_submit($form, &$form_state) { _varnish_terminal_run("purge.url $path"); drupal_set_message("Varnish purged paths matching $path.", 'status'); } + +/** + * Implements hook_file_insert(). + */ +function unl_varnish_file_insert($file) { + _unl_varnish_purge_file($file); +} + +/** + * Implements hook_file_update(). + */ +function unl_varnish_file_update($file) { + _unl_varnish_purge_file($file); +} + +/** + * Instructs varnish to purge the given file from its cache. + * @param stdClass $file as provided by hook_file_[insert,update] + */ +function _unl_varnish_purge_file($file) { + $url = parse_url(file_create_url($file->uri)); + $host = $url['host']; + $path = $url['path']; + + $command = "purge req.http.host == $host && req.url ~ ^$path\$"; + _varnish_terminal_run($command); +} + + -- GitLab