Rarst / fragment-cache

WordPress plugin for partial and async caching.
Other
140 stars 10 forks source link

Add filter so that the cache name can be changed #6

Closed grappler closed 8 years ago

grappler commented 9 years ago

The reason for this change is that I am using Polylang and there are different widgets on the English page to the German page. Both use the same sidebar. This filter would allow me to hook into the filter and add the language to name so that only the widget for that specific language is shown.

Here is an code example

function prefix_fragment_cache_cache_name ( $cache_name, $type, $name, $args, $salt ) {

    if ( isset( $args['args'][1]['pll_lang'] ) ) {
        $pll_lang = '-' . $args['args'][1]['pll_lang'];
    } else {
        $pll_lang = '';
    }

    return 'fragment-cache-' . $type . '-' . $name . $pll_lang . $salt;
}
add_filter( 'fc_skip_cache', 'prefix_fragment_cache_cache_name ', 10, 5 );
Rarst commented 9 years ago

I am not familiar with Polylang, trying to understand your use case. Fragment Cache is not supposed to override if widget is showing overall, only to make its content come from cache instead of being dynamically generated.

Could you clarify how does it interfere with Polylang?

grappler commented 9 years ago

Sure, when Polylang is installed there is an option on every widget which allows you to define for which language the language should display. image At the moment when I first access example.com/en then the widget will be cached in English and so when I switch to example.com/de the English widget will show instead of the second German widget.

The same applies for menus.

Rarst commented 9 years ago

Hmmm... Any idea why? I would guess $widget->id collision maybe?

grappler commented 8 years ago

It is working. I am not sure what I was thinking back then. Closing