开发者

contextual caching of templates with components

开发者 https://www.devze.com 2023-02-04 22:09 出处:网络
I have a page with a menu component. The menu marks the active element with a different CSS class. Now I want to cache each menu item page. The different pages come all from the same module/action, t

I have a page with a menu component. The menu marks the active element with a different CSS class.

Now I want to cache each menu item page. The different pages come all from the same module/action, the difference is just the ID (foo/bar?item=1).

The problem is that the menu is only cached one time, but I need a cache version for every m开发者_C百科enu item.

I just tried the cache option "contextual: true", but I think this does not work because the main template (barSuccess) is always the same.

Do you guys have any idea, how to solve this problem?


You can force cache key by passing the sf_cache_key to the component:

include_component('menu', 'main', array('sf_cache_key' => $sf_params->get('item')));

This way component will be cached for every value of 'item'.

Another way is to use different sets of parameters:

include_component('menu', 'main', array('item' => $sf_params->get('item')));

This way component will be cached for every value of item as well.

In the first solution you force the cache key. It's useful when you need custom logic to decide if the cache should be generated or not.

The second solution relies on fact that component is cached for every combination of parameter values passed to it (there can be more than one of course) .

0

精彩评论

暂无评论...
验证码 换一张
取 消