NP_Cache v1.2 - mix static and dynamic content

home foto blogy kontakt

NP_Cache v1.2 - mix static and dynamic content


I have upgraded my "Plugin-Of-The-Year Winner" (as moraes denoted it), aka NP_Cache, to fully support partial caching. This gives you the ability to cache (statically) most of your page, while still allowing dynamic content plugins like NP_WIE, NP_Views, comment form, and few others to work as they should.

And not only this! Partial cache subscribes to pre-edit / delete / add item and comment events, add / delete category events, and blog events, and clears the item, index, and archive pages as necessary.

NP_Cache is a plugin that creates static pages on request, and it does it fully automatically. What does this mean? If page, or part of it, is requested for the first time, it will capture the output, save it into a static XHTML file, and when it is requested for the second time, it will output this static page in microseconds, without doing tens of SQL queries. It will speed-up your system 10 to 500-times.

NP_Cache allows you to specify which pages should be completely static (i.e. they will be completely saved, with no dynamic content, and refreshed only after a specified cache lifeTime, or, of course, after an event is triggered, like adding an item or a comment), or use special keywords to cache parts of pages that will be cached.

Completely static, fully cached pages, are simple. You don’t need to make any modifications to your skins. Just install NP_Cache.

Now, partial caching is a bit different. You will have to specify which parts of your skins shall be cached, and which not, which shall remain dynamic .

First, you will have to make one small mod (addition) to Nucleus core files. Open file called SKIN.php, and find following lines:

 case 'skintype':
 $condition = ($name == $this->skintype);

Right after these lines add the following code:

 case 'notincache':
 global $np_cache_active;
 $condition = $np_cache_active;

You’re done! After this, NP_Cache plugin, and Nuclues skin parser, will use conditions in skins to parse and/or cache parts of skins as required.

Now, this is how you specify that you want to cache part of your skin:

 ... cached skin part 1 ... 

What does this mean? <%Cache(start,name-of-part1)%> will start the cache. If you have more than one part to cache within one skin, you will have to specify unique skin parts, names. They can be numbers, or letters, but this name has to be unique within one skin (other skins, or other blogs, can use the same name without any problem).

The condition <%if(notincache)%> tells Nucleus parser, that following sections should be processed only if the file is not in cache (NP_Cache plugin). If it is, it will jump to <%endif%> tag instead, thus completely ignoring what is inside (NP_Cache plugin will output a static, cached, XHTML page instead).

Finally, you will have to call <%Cache(stop)%> to stop caching of certain part of your skin and save it to static pages repository.

Now, you wonder, is it possible to cache multiple parts of your skins? E.g. cache everything except a comment form? Here’s an example:

   ... your cached skin header ...
	<%commentform%> <!-- not cached -->
   ... your cached skin footer ...

There are two more parameters you can supply to <%Cache()%> : it is lifeTime of a particular cache, and „stats“ parameter, for statistics. With lifeTime parameter, you can fine-tune your skins and caches as you like. Usage looks like this:

 <%Cache(start,1,1000)%> <!-- in cache for 1000 minutes -->
   ... XHTML ...
 <%Cache(stats)%> <!-- cache statistics --> 
 <%Cache(stop)%> <!-- stop cache -->
 <!-- dynamic content now.. -->

Statistics is displayed by using <%Cache(stats)%>.


Download at:

I have added one more option to NP_Cache version 1.2, which makes static pages dynamic as well, even without modifying core. ;)

Now you can use <!– DYNAMIC_CONTENT_START –> and <!– DYNAMIC_CONTENT_STOP –> keywords in your skins (NOT templates) to specify which parts of your skins will by dynamic, while all the rest will be static.

So, you can define all skins as completely static, except e.g. call to <%commentform%>, which will be surrounded by DYNAMIC_CONTENT_START and DYNAMIC_CONTENT_STOP keywords. In this case, article will be completely cached, and only comment form will be parsed.

Example (keywords have to be entered exactly like this, including exactly one space between comment tags and the keyword):


When using NP_Cache, please uninstall NP_GZip plugin, it is NOT compatible with NP_Cache (as NP_Cache fully takes over GZip functionality).


  1. 1 Radek Hulán 03.06.04, 12:06:27

    support forum thread for NP_Cache:

  2. 2 Jef Pober 03.06.04, 02:06:24

    This is great Radek! Thank you very much (times 1000) for this plugin!

  3. 3 jtheory 27.08.05, 06:08:18

    This is a great plugin!
    You should update your instructions above, though -- I went and modified my SKIN.php file and was starting to sift through my skin files (thinking where I'd have to stick in all of those if statements...) before I read down to the bottom and saw the much simpler DYNAMIC_CONTENT_START/STOP method.

    That should be on top, with the optional full-control method below it for people who need that.