Problem/Motivation

Currently the expire integration doesn't seem to support language prefixes.

Proposed resolution

Add a language prefix pattern if one if the language negotiation based on url prefixes is enabled.

The attached patch should also "enhance" the pattern from something like this:
^/node/113$|^/de-node$|^/fr-node$|^/it-node$
to
^/(|de/|fr/|it/|en/)(node/113|de-node|fr-node|it-node)$

In test runs the pattern seemed to be slightly more efficient.

Remaining tasks

Reviews needed.

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

das-peter created an issue. See original summary.

natew’s picture

I had the same problem and the proposed changes worked for me. I needed to re-roll the patch to apply to 7.x-1.0-beta3.

das-peter’s picture

After finding this issue #1481136: Avoid "Connection reset by peer" on large purge list by batching paths I decided to make a re-roll of this and include the change made there.

@natew May I ask you to suffix patches, not created against the latest dev, with "[patch-name]-do-not-test.patch"? Patches should generally be created against latest dev - one reason for this is to make sure the testbot can run, for more details see: https://www.drupal.org/patch/submit If you mark them with "do-not-test" the testbot isn't triggered and the ticket status isn't set accidentally to "needs work".

natew’s picture

Thanks das-peter, I wasn't aware of this and will do so in the future. I apologize about any inconvenience this may have caused.

candelas’s picture

Thanks. The #3 patch works.

candelas’s picture

I have this patch working for 3 months, so I consider that it is tested.

candelas’s picture

Status: Needs review » Reviewed & tested by the community
candelas’s picture

FileSize
1.97 KB

I actualize to varnish 7.x-1.1 I had to remove this because it was already applied.

--- a/varnish.module
+++ b/varnish.module
@@ -106,17 +106,19 @@ function varnish_expire_cache($paths) {
       $host_buckets[$parts['host']][] = $parts['path'] . (!empty($parts['query']) ? '?' . $parts['query'] : '');
     }
     foreach ($host_buckets as $host => $purges) {
-      $purge = implode('$|^', $purges);
-      $purge = '^' . $purge . '$';
-      varnish_purge($host, $purge);
+      varnish_purge_paths($host, $purges);
     }
   }

Here the new patch from #3 that works with 7.x-1.1 and last dev. I put to needs review, since I have not tested it enough.

candelas’s picture

Status: Reviewed & tested by the community » Needs review
Max86’s picture

Hi thx for patch.
#8 worked for me for nodes with multilanguage support.
But I run in problem that front page doesn't clear on node save, may be it is issue of expire module?

candelas’s picture

@Max86 I am not having problems, but you can make a rule and I also use the https://www.drupal.org/project/ui_cache_clear because sometimes I make in dev things that I pass to production and I need to clear cache for a page.

dshields’s picture

Status: Needs review » Reviewed & tested by the community

#8 works perfectly for me! RTBC

rv0’s picture

#8 works fine for me

just one tiny detail, I believe it does not work for the frontpage with this approach because it makes the '' path into a 'prefix/' path, while for flushing the front page requires '/prefix'

For now I quickfixed it for my case using hook_expire_cache_alter()

  // Make sure the French homepage also gets flushed.
  $front_path = variable_get('site_frontpage', 'node/761');
  $fr_front_path = i18n_variable_get('site_frontpage', 'fr', 'node/1382');
  if (isset($urls['front-path']) || isset($urls[str_replace('/', '-', $front_path)])) {
    $urls[str_replace('/', '-', $fr_front_path)] = $fr_front_path;
    $urls['fr'] = 'fr';
  }

of course this is a very specific fix for my usecase :)

Marko B’s picture

This certanly can be fixed here, but isn't it a wrong place to fix? Expire module is sending the list of urls that need to be purged and it is doing it wrong. There are issues posted about that there

https://www.drupal.org/node/2291643
https://www.drupal.org/node/2267305
https://www.drupal.org/node/2291643

So if its solved there, this patch is not really needed and not a nice way to fix this problem.

das-peter’s picture

Somewhat related to the comment of Marko B:
There's now also Drupal 8 Cache Backport and Render Cache both supporting setting the X-Drupal-Cache-Tags HTTP header.

Below an example how you can utilize this to handle the varnish cache:

$host = _varnish_get_host();
    _varnish_terminal_run(array('ban req.http.host ~ ' . $host . ' ' . $additional_condition . ' && obj.http.X-Drupal-Cache-Tags ~ "(' . implode('|', $tags) . ')"'));

I hadn't time jet to make a nice integration into this module but think that would be a neat addition as it is way more efficient.

MiSc’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

Closing this, should be solved in expire module.