Let me also repeat my example with all codes, so it might be useful for others -
Some form is being built with cities dropdown and we want to optimize the following code for the first user who requested page without present Couch cache of that complete page -
- Code: Select all
<cms:input type='dropdown' name='cities'
opt_values="<cms:pages masterpage='cities.php' skip_custom_fields='1' limit='100000' >
<cms:show k_page_title /><cms:if k_paginated_bottom = '0'>|</cms:if>
</cms:pages>"
/>
We can optimize it like this -
- Code: Select all
<cms:if "<cms:not "<cms:exists 'cache/cities_html.inc' />" />" >
<cms:write 'snippets/cache/cities_html.inc' truncate='1'>
<cms:embed 'cache/cities_code.inc' />
</cms:write>
</cms:if>
<cms:input type='dropdown' name='cities' opt_values="<cms:embed 'cache/cities_html.inc' />" />
Where cities_code.inc file would look like -
- Code: Select all
<cms:pages masterpage='cities.php' skip_custom_fields='1' limit='100000' >
<cms:show k_page_title /><cms:if k_paginated_bottom = '0'>|</cms:if>
</cms:pages>
And you can place similar code to manually rebuild cache by, for example, visiting cities.php non-executable template which only updates the snippet with cities.
- Code: Select all
<cms:write 'snippets/cache/cities_html.inc' truncate='1'>
<cms:embed 'cache/cities_code.inc' />
</cms:write>
As a last thing - It can be effective in case there are multiple parts of such "custom caches" and multiple places of where a cities list is needed. If your website only has one "heavy" page - then it might be useful to instruct admins to visit that page in browser..
Alternative idea - hook on event which triggers after page is saved in backend by admin - and request an url in background anonymously via curl (can employ this function here -
https://github.com/trendoman/utility-fu ... e_url.html ). It will definitely build the desired cache for a given url.