blog.Resource

Archive:

News-Feeds:


RSS 2.0
RSS 0.91
RDF
ATOM 0.3
July 24, 2008

Don't Wear Out the Clear Cache Button

Category: Ron Hall

Reduce your manual cache clearing by 95% with a single line of TypoScript.

TYPO3 has a sophisticated caching system that helps our sites run faster. This is a great thing, but sometimes it gets in the way.

For instance, when you make a change to site-wide content you need to remember to clear the cache in order for it to show up. Also, when actively developing a site, I find myself having to clear the cache every minute and a half in order to check the changes I am making to data structures, templates and TypoScript. To make matters worse, TYO3 4.2 now makes you use a drop down menu to clear the cache which takes just that much longer (Just to be clear though, I really like 4.2).

Anyway, a few weeks ago a I found a single line of TypoScript that has reduced my cache-clearing duties by 95%. The TS property I am talking about is TCEMAIN.clearCacheCmd. I know, I know. The veteran TYPO3 heads are all saying, "Who doesn't know about that." Well, for one, me even though I have been around the TYPO3 block a few times. My guess is that there are more than few others like me out there.

How clearCacheCmd is Normally Used

Before I get into the really cool part, let me tell you how this is normally used. Let's say you have a blog with the posts stored in a SysFolder. There is an archive view on a page (id=45), a single view on a page (id=53) and latest view on a page (id=60). You would want to put the following in the page TSconfig of the SysFolder where you store your posts.

TCEMAIN.clearCacheCmd = 45,53,60

What you have done is to told TYPO3 that when ever you add or change a record in the SysFolder then the cache for pages 45, 53 and 60 should be cleared. It works recursively so if you have other folders nested inside the main folder then records changed inside them will trigger the cache clearing as well. This way blog authors do not have to clear the cache every time they edit a post.

Now for the Cool Part

That is all a good thing, but this is what really got me excited (which will show it doesn't take much to get me excited).

I consistently set up a group of SysFolders nested like this:

Site Resources
     TypoScript
     Generated Content-1
     Generated Content-2

Their functions are:

  • Site Resources (stores TemplaVoila data structures and template objects)
  • TypoScript (stores various TS libraries like header, footer, menus, etc. which I include in the main site TS template)
  • Generated Content-1 (stores site-wide content like ads, login boxes, etc.)
  • Generated Content-2 (same function as Generated Content-1)

In the page TSconfig of the Site Resources folder I add this line:

TCEMAIN.clearCacheCmd = all

So, what happens? The entire site cache is automatically cleared anytime I make a change to TypoScript, side-wide content, data structures, template objects or anything else in those SysFolders.

Anyway, I'm excited.


comments

comment #1
Gravatar: Andri Viiand Andri Viiand July 24, 2008 07:14
Thank you Ron!

Saved many clicks for me and whats even more better - no more angry phonecalls from secretary-type editors complaining about stuff not showing up on site :-)

comment #2
Gravatar: Andreas Kundoch Andreas Kundoch July 24, 2008 08:49
While developing you could also use 'config.no_cache = 1' in your TypoScript setup. Don't forget to remove this or set to 0 when finished.

comment #3
Gravatar: Steffen Müller Steffen Müller July 24, 2008 12:10
Don't use config.no_cache! It's going to be depredacted.
Since 4.2 we have
$TYPO3_CONF_VARS['FE']['disableNoCacheParameter'] to disable no_cache globally and it's meant to be disabled be default at some time. So don't rely on this feature.

comment #4
Gravatar: Ron Hall Ron Hall July 24, 2008 14:47
I do not recommend using a global no cache. It will work but is too easy to forget to change it after development is finished. Especially if the site is already live and you are only making a few adjustments to the TS. Using the clearCacheCmd in the way I suggested means that it is clearing the cache when it makes sense to do so.

comment #5
Gravatar: Dmitry Dulepov Dmitry Dulepov July 24, 2008 21:06
It is not a good idea to clear all cache. Imagine that you have 10000 pages + many tt_news. If you clear all cache and you have high traffic web site, this will badly affect performance of the site.

It is much better to clear cache only for necessary pages. "all" is easy but bad.

comment #6
Gravatar: Ron Hall Ron Hall July 24, 2008 21:28
Yes, Dimitri, in situations like a blog I would only set this up for the pages that need to be cleared. However, when it comes to the records that are contained in the sysFolders I where I use "all" the entire site cache needs to be cleared. Things like site-wide generated content and TS templates affecting the entire site.

comment #7
Gravatar: Andreas Kundoch Andreas Kundoch July 25, 2008 09:56
@Steffen: You're right - and I know this :-) It's not good but quick and dirty to use no_cache = 1, and its gonna be depreacted soon. Anyway I was talking about an LPE setup with an internal development server where it's "ok" to deactivate caching. I never meant to set this on a live system.

comment #8
Gravatar: Nils Hodyas Nils Hodyas July 30, 2008 11:08
I see why you are excited (and I was too, when I found out ;-)).
But alas, we're including our TS from a static document (for safety reasons), so I'll have to go on pushing the button :-(

comment #9
Gravatar: Ralph Roeder Ralph Roeder August 12, 2008 23:50
Relaunching our site with typo is difficult enough. As a secretary-type editor i´m a bit confused now which cache clear method i should use.

Sorry, comments are closed for this post.