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.

Filed under: Features 1 Comment
29Dec2010

Typed templates

A very interesting concept in Fatwire is that templates are "typed".

Unfortunately, this is also a concept very easily misunderstood.

The idea is:

  • You define a number of content types
  • Then you apply a set  of standard templates to that content type (like method of a class in OOP)
  • Name of the templates should be standardized

For example, you can have News, Articles and Blog posts as content types.

The best way is to decide for a number of common way of render the content: for example: Summary, Detail, Link.

So you can expect to have something like this:

News/Summary
News/Detail
News/Link
Article/Summary
Article/Detail
Article/Link
Blog/Summary
Blog/Detail
Blog/Link

If you follow those conventions,  combining templates becames very easy. You can add in a page a Blog or an Article and then replace with a News.

Just call the template as it should (using a call:template that specify the c and only the Summary - the "relative" way). This way rendering an Article as a summary is the same as rendering a Blog as a summary.

But you start to give different names to template without following any conventions... your code will became a mess.

And you won't exploit the "typed template" approach built-in in Fatwire.

28Dec2010

Fatwire multiple caches

Fatwire Content Server has many caches, and it is very important to understand all of them.

Here a short list of the caches you have to consider

1. Content Server Cache

This is a content cache (html primarily) This cache is stored on disk. It can became very large because it caches a rendered html in full. It is fast but it read the content from disk and this can slow down a busy website.

2. Satellite Server Cache

This is another content cache (html). This cache is stored in memory. To limit the memory required, it does not store the full html but keeps the content split in different pieces, and reassemble it on demand.

3. Blob Server Cache

This cache is for binary content. It is a memory cache as well up to a certain limit, then it became a disk cache.

4. ResultSet Cache

This cache is for the result of queries. To avoid running the same query again and again, Fatwire store the result and keep it in memory for a while. Since many queries are the same, this can help a lot. Actually, thank to this cache, Fatwire often performs well even with very slow databases.

Filed under: Features 1 Comment