New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Statamic Caching for Multi-Lingual sites #1277

Closed
matteobarone opened this Issue Feb 28, 2017 · 12 comments

Comments

Projects
None yet
5 participants
@matteobarone

matteobarone commented Feb 28, 2017

Expected behaviour

We have a bilingual website, we expect that a page would be cached both in original language and translated.
www.example.com -> loaded first and cached
www.example.com/it -> we can’t see the translated page, but still the original one

Actual behaviour

Even if the url is different, the first page loaded is the only version cached and so reachable.

Steps to reproduce

  1. Load the home (www.example.com), and see the original page
  2. Switch language
  3. Load the home translated (www.example.com/it/), and see the translated page
  4. All this with the static cache enabled

Server configuration

Operating system:
OSX

Web server:
Apache

PHP version:
5.6.28

Statamic version:
2.5.3

Updated from an older Statamic or fresh install:
Update from statamic 2.1.9

List of installed addons:
none

Logs

Caching.yaml file setting:

stache_always_update: false
static_caching_enabled: true
static_caching_type: cache

@dojchek

This comment has been minimized.

dojchek commented Apr 27, 2017

I also hit the same issue.. This one is actually mandatory for me.
As soon as I add 2nd language cache crashes and starts to behave very strange.
Is there a version where this used to work?
@matteobarone How did you deal with this in the end?

@matteobarone

This comment has been minimized.

matteobarone commented May 2, 2017

@dojchek We figure out that the cache works if there is a different path of the page.
So for example we have:

If we used:

the only page cached is the original one (english)

So we used different slug for every page/entry.

The only problem was the homepage, because we had:

and we deal with:

Hope this will help you.

@dojchek

This comment has been minimized.

dojchek commented May 2, 2017

@matteobarone
Thank you man! I actually have an issue with home page - will try to do it like you suggested, hopefully it will work out. The only diff is that I'm using full measure caching..
To be honest, I switched to grav in the meantime since I had so many troubles with statamic. I will still give one more chance to statamic since I already purchased it.
Thanks!

@jasonvarga

This comment has been minimized.

Member

jasonvarga commented May 10, 2017

Hey guys sorry for the delay on this.

I got it working using these steps. Let me know if you have any success.

  • Symlink static to it/static
  • In both your root .htaccess and your it/.htaccess, change the rewrite rules to this:
RewriteCond %{DOCUMENT_ROOT}/static/%{REQUEST_URI}/index.html -s
RewriteCond %{REQUEST_METHOD} GET
RewriteRule .* static/%{REQUEST_URI}/index.html [L,T=text/html]
@matteobarone

This comment has been minimized.

matteobarone commented Jun 1, 2017

@jasonvarga I'm not using full static cache as @dojchek, but only stache (I have not the static folder).

I'm fighting with another problem now: I can't cache same pages of different domains that points to the same server (e.g. luceplan.com and luceplanusa.com). Same problem: the first I load, is the first cached. You know if there is a workaround?

@andypillip

This comment has been minimized.

andypillip commented Jun 5, 2017

@jackmcdade sorry but since Statamic claims to be multilingual, and offers caching, to me this is a bug, not a feature request.

@jackmcdade jackmcdade added bug and removed feature request labels Jun 5, 2017

@andypillip

This comment has been minimized.

andypillip commented Jun 5, 2017

@jasonvarga could you please elaborate more how the Caching decides to create a static html file?

I'm running with only one .htaccess file to avoid redundance, with the following core rewrite rule:

RewriteRule ^(en/)? $1index.php [L]

From Statamic's perception, this shouldn't change anything, right?

But when I link static → it/static, and add your REQUEST_URI based rules, I still see the same problem: IT pages overwrite default pages (and vice versa).

When creating the static HTML files, Statamic is ignoring the /it/ from the path.

@andypillip

This comment has been minimized.

andypillip commented Jun 5, 2017

I conducted some experiments, also with an extra /it/.htaccess.

Statamic will always leave out the /it/ when creating the static cache files. Whether I link static/ → it/static/ doesn't make any difference, of course.

But if Statamic would use it/static for the Italian cache, one could link /static/it → /it/static and everything would work.

@dojchek

This comment has been minimized.

dojchek commented Jun 5, 2017

@andypillip Completely agree with you on this one.
I was using nginx conf instead of .htaccess, and couldn't get it work as well. Was searching for the solution on so many threads and slack channel, but no matter what I did I couldn't make it work. This thread was the closest match to my issue..
Those two (i18n/full-measure cache) simply don't hand by hand without some additional sneaky config (which I couldn't find in any of the docs).

@andypillip

This comment has been minimized.

andypillip commented Oct 5, 2017

@jasonvarga is it possible that static_caching_invalidation is ignoring localized cached files?

I tried this:

static_caching_invalidation:
  collections:
    assistant:
      urls:
        - /assistent
        - /assistant

and also /en/assistant in the last line.

It works for the default locale /assistent, but neither will delete the static cache file on save.

@andypillip

This comment has been minimized.

andypillip commented Oct 5, 2017

Also, apparently static_caching_exclude uses slugs without locales, which is not mentioned in the docs.

Because of before mentioned bug I'd like to exclude my English home page from the cache, which is not possible. It might not make sense to exclude locales from caching, though. Just documenting it (:

@andypillip

This comment has been minimized.

andypillip commented Oct 5, 2017

@jasonvarga is there a reason you're suggesting separate web roots with copying several files, instead of one dynamic rewrite rule?

I have the feeling that several issues and workarounds could be avoided with a cleaner setup:

RewriteRule ^(en/)? $1index.php [L]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment