thoughtco/statamic-cache-tracker

Unpublishing a nav entry does not clear cache

Closed this issue · 2 comments

Hi, I don't know if you remember this post I opened on Statamic/ideas. I was requesting that unpublishing an entry that is contained in a nav should invalidate the cache for all urls using that nav.

I've been testing this out locally with your package but publishing / unpublishing an entry in my main nav but my static cache is not being cleared.

Bear in mind that I am using Blade and some non-standard methods of rendering my navigation, for example this how I render my nav:

@for(\Statamic::tag('nav:main')->params(['select' => 'title|url|is_current'])->fetch() as $item)
  <x-header-nav-link 
    href="{{ $item['url'] }}" 
    :active="$item['is_current']"
    >{{ $item['title'] }}
  </x-header-nav-link >
@endforeach

It seems that the nav tag call is being detected:

@dump(\Thoughtco\StatamicCacheTracker\Facades\Tracker::cacheStore()->get('tracker::urls'))

    "tags" => array:12 [▼
      0 => "nav:main"
      1 => "nav:about"
      2 => "nav:support"
      3 => "nav:business"
      ....

Is this a bug or am I missing something?

Thanks!

As its tracking the nav, then you could use an entry saving listener to clear the cache, eg:

if ($entry->isDirty('published')) {
	Tracker::invalidateTag('nav:main');
}

The reason its not clearing automatically is its not tracking the entry id, which it does in antlers.

Ah okay. Looks like need to go down the custom invalidator road.

Thanks for the explanation and advice.