Support » Plugin: WP REST Cache » WPML issue: content is not cached language wise

  • Resolved bobo_italy

    (@bobo_italy)


    Hi! Fantastic work on this plugin, when this issue will be fixed it will save us a lot of headaches!

    We run a website with WPML and the content is only cached in the first opened language.
    For example if I open:
    http://www.example.com/wp-json/wp/v2/posts
    I will see Italian (in our case) posts, then opening:
    http://www.example.com/en/wp-json/wp/v2/posts
    I will see the same response as before, even though without the plugin that URL returns English posts. Furthermore, if the order of openings is reverted, both URLs will return English content.

    Also, I have a feature request: a setting to disable the hit counter for the cache to further cut down the load on the server.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis

    (@rockfire)

    Hi @bobo_italy

    Thank you for using our plugin!

    We have investigated your issue and were unable to reproduce it. However we did find some strange (?) behaviour in WPML. We set-up a test site with two languages: English (default) and Dutch (/nl/). Now if we visit http://www.example.com/wp-json/wp/v2/posts it shows English posts, then opening http://www.example.com/nl/wp-json/wp/v2/posts it shows Dutch posts. So far as one would expect.
    If we visit http://www.example.com/wp-json/wp/v2/posts?lang=nl it shows Dutch posts, if we then visit http://www.example.com/wp-json/wp/v2/posts it also shows Dutch posts. This is all with our caching plugin disabled. So it seems WPML is doing something strange, which maybe is also causing your issue? Just to be sure could you try your usecase with our plugin disabled?

    If you don’t see your issue with our plugin disabled, could you check Settings > WP REST Cache > Endpoint API Caches and find the caches for /wp-json/wp/v2/posts and for /en/wp-json/wp/v2/posts and check the details, it will show you the cache contents. Are they indeed the same?

    bobo_italy

    (@bobo_italy)

    Hi Richard, I think I understood the matter… There’s nothing wrong with WP Rest Cache in this regard, it’s just how WPML works. It gives priority to the language chosen via cookie/session over the url in the API, in other words it works in a stateful way. When you visited the URL with “?lang=nl” it kept the language selection in your session or cookie and then presented you with the same language, even if the URL said otherwise.
    It happens also when you switch language from the admin panel and load an API url, and that was when I realized it’s working this way.
    Sorry for the bogus bug report. Maybe you should add a line or two in the FAQs or Readme!
    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WPML issue: content is not cached language wise’ is closed to new replies.