Forums / Developer / Caching causing problem for XML feed

Caching causing problem for XML feed

Author Message

Michael Hall

Monday 28 January 2008 8:34:29 pm

We have a page on our municipal council website which displays a 4 day weather forecast using an XML feed. The feed is working, but the page on our production site often displays data up to four days old, presumably because of caching. The same page on our dev site, which is not cached, always displays correct data.

The data is displayed using <custom name> tags in a "page" that is actually the description field of a published folder.

To force an update on the production site, I have to manually clear the Content View Cache. It will occasionally update itself, but without any discernible pattern.

As an eZ publish newbie, I don't know where to start trying to fix this. I've tried adding a {cache-block expiry=3600}{/cache-block} around the design template that publishes the forecast data (it is part of a custom extension), but it has no effect.

Do cache blocks work at this level?

Should I set up a cron job to force a daily clearance of the Content View Cache?

Is it normal for a site to go 3 or 4 days without the Content View Cache being renewed?
Should this cache should be renewed every two hours by default?

Any other suggestions? We only need this particular page/cache to be renewed once or twice a day.

I've read the documentation on cache-blocks but haven't found it particularly useful so far.

Łukasz Serwatka

Tuesday 29 January 2008 5:26:10 am

Hi Michael,

Could you write more how did you setup that XML feed? Was it via admin interface Setup->RSS or via layout module with enable XML header? Looks like view cache is not configured properly.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Michael Hall

Tuesday 29 January 2008 3:15:10 pm

This was set up as an extension. A custom class fetches the data which is displayed using a custom template. I used the example on the eZ website for fetching currency data as a model.

Definitely not set up using RSS. I don't recall coding anything specific about XML headers.

Łukasz Serwatka

Wednesday 30 January 2008 12:23:12 am

I assume that you have build some fetch functions and you want to refresh content when source changed.

You can either disable view cache for that template:

{set-block scope=global variable=cache_ttl}0{/set-block}

http://ez.no/ezpublish/documentation/incoming/how_to_set_cache_expire_time_or_disable_cache_in_template

Or introduce a TTL variable in your PHP that will check last update and current time, then perform view cache clearing.

// Clear for node with ID 123
$nodeID = 123;
eZContentCache::cleanup( array( $nodeID ) );

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Gaetano Giunta

Wednesday 30 January 2008 12:58:59 am

As a side note: you should set up a correct pagelayout template and definitely content-type headers if you plan to produce xml via templating.

It is in fact quite easy to do, via the layout module. Just add this in an override file for layout.ini:

[xml]
PageLayout=xml_pagelayout.tpl
ContentType=text/xml

Then
- set up xml_pagelayout.tpl to contain the xml prolog
- use urls of the form ez/layout/set/xml/path/to/content to access your data in xml display mode

I would recommend creating a new view, eg: xml for displaying data as xml. This way you can still make use of node_view_gui and attribute_view_gui inside your templates. TEmplates to be done: /node/view/xml.tpl and content/datataype/view/xml/datatypexx.tpl

Principal Consultant International Business
Member of the Community Project Board