0



31Dec2010

What cache dependencies are

One of the best kept "secret" of Fatwire is the cache invalidation mechanism.

Rendering an asset is slow.

Really slow. It is slow because  there are many database queries involved. So, once a template is rendered, the result is cached (at least, if you have enabled caching for that template).

But, when you cache a component, what happens if the source asset change? I mean, what happens if you render an article, and then the article is updated? Of course, when the source asset is updated the cached element is invalidated.

Asset dependencies

There is actually a database table tracking all the dependencies. For each cached element (called "pagelet") in the database,  a dependency is stored in that table. That is, the information:

"which pagelet must be invalidated when an asset is updated".

Publishing invalidate the cache

When you publish it happens that the cache is updated, as well.

For each published asset,

1. all the dependencies are searched for

2.  all the cached pagelet that depends on the published asset are invalidated.

Please note that this happens only for the pagelets that have dependencies on the published assets.

Smart Cache

So you don't need to rebuild the whole cache, but only the pagelet that are  invalidated. Just a bunch of them. Those who depends on the new assets.

It is a smart and powerful mechanism.  Unfortunately, is is also a mechanism easy to break if you don't follow a design and some simple rules in coding templates.

Or worse, if you ignore the caching and the dependency mechanism.

Posted by msciab
31Dec2010