statamic / v2-hub

Statamic 2 - Feature Requests and Bug Reports
https://statamic.com
95 stars 5 forks source link

Static cache invalidation for localized content #2414

Closed fredmarmillod closed 5 years ago

fredmarmillod commented 5 years ago

Describe the bug When full measure caching is configured (according to the documentation). It seems like invalidation rules won't be applied correctly. As I understood, when updating content from the cp, the FileCacher is always getting the default language when building the invalidation path.

A fix that works for me I was able to fix the problem by editing Statamic\StaticCaching\FileCacher::getCachePath:

public function getCachePath($locale = null)
{
    $paths = $this->getCachePaths();

    if (! $locale) {
        // Before
        $locale = $this->config('locale');

        // After
        $locale = request('locale', $this->config('locale'));
    }

    return $paths[$locale];
}

To Reproduce Steps to reproduce the behavior:

  1. Configure caching as below:

    stache_always_update: true
    cache_tags_enabled: true
    static_caching_enabled: true
    static_caching_type: file
    static_caching_file_path:
    fr: static
    de: de/static
    it: it/static
    static_caching_invalidation:
    collections:
    news:
      urls:
        - /
        - /de/ # the final slash is required for my fix to work
        - /it/
  2. The root folder should have this structure

    - /
    - statamic
    - site
    - ...
    - /de
    - static
    - /it
    - static
  3. Create a collection named "news" with an entry

  4. Load the homepage in multiple locales to create static files for each

  5. Edit the entry you created in each language

Expected behavior Static files in each locale path should be deleted

jnbn commented 2 years ago

Seems like this problem still exists @fredmarmillod . Or at least i'm having the same problem on full static cache

Are there any suggestions or updates about it or did you find anything else? @jasonvarga @jackmcdade

jnbn commented 2 years ago

I think we have a different case, sorry.

We have 2 locales.

Tr is our primary locale and En is our second...

We have pages with different slugs on different locales.

Let our pages be: hakkimizda/biz-kimiz and about/who-we-are

When we try to update about/who-we-are from cp, $page->url still resolves to hakkimizda/biz-kimiz on invalidatePageUrls @ StaticCachingInvalidator resulting only (turkish) page to be removed from static cache. (but we're editing the page in english)