| Name | Cache Plugin |
|---|---|
| Vendor | Bob Swift, Jason Dillon, and other contributors |
| Authors | Bob Swift |
| Homepage | http://confluence.atlassian.com/display/CONFEXT/Cache+Plugin |
| Issue Management | http://developer.atlassian.com/jira/browse/cache |
| Continuous Integration | n/a |
| Categories | Content Macros |
| Most Recent Version | 3.1.0 |
| Availability | Confluence v2.4.2 to v2.10 |
| State | Stable |
| Support |
|
| License | Freeware / Open Source (BSD) |
| Price | Free |
| Release Docs | http://confluence.atlassian.com/display/CONFEXT/Cache+Plugin |
| Java API Docs | n/a |
| Download Source | http://svn.atlassian.com/svn/public/contrib/confluence/cache-plugin/trunk |
| Download JAR | cache-plugin-3.1.0.jar |
Additions and corrections to above
| JVM requirements | Java 1.4 and above | ||
|---|---|---|---|
| Installation requirements | or upload from Confluence's administration console.
|
Description
Allows cache control of page-level elements.
Caches the rendered contents of the body of this macro. Very useful when using macros that might be slow to render content, but where it does not really need to be dynamically generated for each and every request. Specifically, this can improve performance for accessing dynamic data from sql, excel, and similar macros. Cache will be refreshed if the body of the macro changes or if attachments to this page have been added, removed, or have newer versions. The cache applies to all users that view this page.
Based on OSCache.
Documentation
- Help available in the notation guide.
Parameters
- refresh - Cache refresh period. Default is a day. A number will be treated as seconds. A number followed by one of the following characters will be treated as follows:
- s - seconds.
- m - minutes.
- h - hours.
- d - days.

Any data after a s, m, h, or d is ignored. For example, 10days is the same as 10d or 10 days.
- cron - Cron-like expression for finer grained expiration. See Cron Expressions.
- showRefresh - Show a refresh icon if showRefresh=true. Default is false. When the refresh icon is clicked, the cache for this macro will be discarded forcing the data to be regenerated.
- showDate - Show the date and time that data was generated if showDate=true. Default is false. The date field follows the refresh icon and before the data.
- checkAttachments - Default is true. If true, the cache will be refreshed if there is any change in the attachments on this page. This includes adding, removing, or changing the version of any attachment. For instance, if you are caching the rendering of the an excel spreadsheet, then the data will be refresh if the attached spreadsheet is updated.
- title - Title to show when mouse is over the refresh icon. Default is "Refresh".
Customization
- For normal usage, properties do not need to be changed.
- Properties for the cache behavior are specified in .../WEB-INF/classes/oscache.properties.
- The properties file ships with Confluence and applies to the cache macro and other components using the defaults for the OSCache support. The default is:
cache.memory=true cache.capacity=100
- The capacity property equal to 100 means that 100 distinct renderings of the cache macro will be cached. Additional distinct renderings will replace previously cached entries. You should increase the capacity only if you used the cache macro in many places (over 100) that are accessed regularly and the extra JVM memory used will be acceptable.
Usage
{cache}
Something to cache for a day
{cache}
{cache:refresh=30m}
This will be cached for 30 minutes
{cache}
{cache:refresh=2 hours}
The excel data will be cached for 2 hours
{excel:file=^Report.xls}
{cache}
{cache:cron=30 * * * *|showRefresh=true|title=Refresh data from database}
This will be cached until 30 minutes past each hour of the day
{sql:dataSource=ReportDS}
select * from report
{sql}
{cache}
{cache:refresh=1d|showRefresh=true|showDate=true}
{beanshell}
System.out.println("Hello world " + (new Date()) );
{beanshell}
{cache}
Advanced Example
Tips and Techniques
Compatibility With Other Macros
Macros known to be allowed in the body of the cache macro
- SQL Plugin
- CSV Macro
- Beanshell Macro
- Groovy Macro
- Jython Macro
- Excel Plugin
- HTML Plugin
- XSLT Macro
- Jasper Report Plugin - with some exceptions for images
- Confluence Chart Plugin - see Site Statistics for examples.

Caching chart images If you use the cache macro around the chart macro, you must use the attachment support provided by CHRT-38.
Macros known to not work with the cache macro
- {excerpt} - if the excerpt is defined within a cache, you will not be able to retrieve it's contents using the {excerpt-include} macro.

- Flowchart macro and other graphviz related macros
- Other macros that generate dynamic images
Other information
Cache Refresh
- To force all cache macros on a page to refresh, use a request attribute
- Example
http://localhost/display/SCRIPT/test?refresh=true
- Example
Cache Flushing
- To force all or portions of the entire cache to be flushed, use a request attribute on a page that uses the cache macro
- Example - all
http://localhost/display/SCRIPT/test?cache-flush=all
- Example - refresh first cache macro on page
http://localhost/display/SCRIPT/test?refresh=1
- Example - all
Warnings, restrictions, and dependencies
This macro support Macro Security Plugin
Screenshots
Version History
| Version | Date | Author | Notes |
|---|---|---|---|
| 3.2.0-beta | 03-Feb-2008 | Bob Swift | release notes |
| 3.1.0 | 24-Jun-2007 | Bob Swift | release notes |
| 3.0.2 | 06-Oct-2006 | Bob Swift | Inline (works better with chart macro) |
| 3.0.1 | 26-Sep-2006 | Bob Swift | Java 1.4 compatible |
| 3.0 | 24-Sep-2006 | Bob Swift | release notes |
- Previous versions were included in Scripting and External Content Macros
Release Notes
- 3.2.0 beta
When: 03-Feb-2008
Who: Bob Swift
What: - Beta only - not in plugin repository
- See Indexing External Content for information
- Tested on 2.5.2 and 2.7.1
- 3.1.0
When: 24-Jun-2007
Who: Bob Swift
What:


Comments (71)
Jan 23, 2006
Awax says:
Wonderfull for the SQL macro !Wonderfull for the SQL macro !
Jan 23, 2006
Jason Dillon says:
I think it should be possible to add support to cache generated images too... co...I think it should be possible to add support to cache generated images too... could probably post-process the cached buffer, check for links, cache them and then use a new URL.
Aug 03, 2007
Bert Pluymers says:
Caching images would be a really nice feature. I am using the latex plugin, whi...Caching images would be a really nice feature. I am using the latex plugin, which sometimes makes pages slow to render, because it generates the png files again every page view, while the content is essentially static.
I installed the cache plugin specifically for use in combination with this plugin, so it would be nice if you could give the above suggestion a try.
Jan 23, 2006
David Peterson [CustomWare] says:
Nice macro(s) guys. I'm curious Bob, how do you generate an id automatically? Th...Nice macro(s) guys. I'm curious Bob, how do you generate an id automatically? The 'X'th {cache} macro on the page? What happens if an extra {cache} is at the top of the page? Will it stuff up the rest of the macros on that page?
Jan 23, 2006
Bob Swift says:
Yes, it will. And that could be prevented by an optional id parameter. But it i...Yes, it will. And that could be prevented by an optional id parameter. But it is just a cache, so it would just force a refresh. I would prefer that to requiring user to specify an id.
Jan 23, 2006
David Peterson [CustomWare] says:
Yeah, if a page edit forces a refresh that should be fine. I would also prefer t...Yeah, if a page edit forces a refresh that should be fine. I would also prefer to avoid an id if possible, and this seems like a reasonable solution here.
Jan 23, 2006
Bob Swift says:
With this implementation, a page edit does refresh anyway. However, the "body" ...With this implementation, a page edit does refresh anyway. However, the "body" changed support I have will be finer grained. But changing order will force refresh of those that are affected by the change.
Jan 23, 2006
Jason Dillon says:
I'm not sure how body changed support would work... seems like to detect that yo...I'm not sure how body changed support would work... seems like to detect that you need the body first, meaning you have to render, which defeats the purpose of the cache in the first place.
Got some magic I'm unaware of?
Jan 23, 2006
Jason Dillon says:
I had thought about doing some auto id generation, short of what is already done...I had thought about doing some auto id generation, short of what is already done... cache key is the spaceKey:pageName or spaceKey:pageName.id if an id attribute is given. Wasn't really sure if there was an easy way to auto-generate an id for multiple cache blocks... and make them predictable, so you could flush a cache'd block using cache-flush=entry=some_id.
That said, if there is an easy way to auto-generate an id, no reason not to add support for it IMO.
Jan 23, 2006
Guy Fraser says:
Atlassian are going to have a tough time judging the Codegeist!Atlassian are going to have a tough time judging the Codegeist!
Jan 23, 2006
Guy Fraser says:
Would it be possible to cache by group/user/privs using similar params to David'...Would it be possible to cache by group/user/privs using similar params to David's show-to and hide-from macros? That way you could still implement caching even for pages that contain content for mixed user groups by simply stating who the cache relates to?
Jan 23, 2006
Jason Dillon says:
You mean, like cache for anonymous = 1h and cache for confluence-administrators ...You mean, like cache for anonymous = 1h and cache for confluence-administrators = 5m or something like that? More control over the cache refresh period based on a user or group specification?
Jan 23, 2006
Bob Swift says:
It is possible to add more key values (like user) but not sure what group you co...It is possible to add more key values (like user) but not sure what group you could assign. User based cache would certainly limit the value of the cache - more cached data , overlow forcing refresh, and fewer hits. For groups, are you thinking of looping through all groups the specific user belongs to and see if there is a cache associated with that group name??? And what group would that rendering be associated with?? Certainly raises a lot of complications.
Feb 10, 2006
Guy Fraser says:
I've added some ideas to SCRP-54 I agree that per-user cache would in most case...I've added some ideas to SCRP-54
I agree that per-user cache would in most cases be fruitless, however for small companies (eg. 25 users on an intranet) it would be useful.
Jan 24, 2006
Guy Fraser says:
This macro owns! Even on normal pages that contain lots of wiki formatting (and ...This macro owns! Even on normal pages that contain lots of wiki formatting (and layout macros, etc) this macro gives a noticable improvement in speed.
Jan 24, 2006
Jason Dillon says:
Can you guys (or anyone) recommend a good approach to generating unique and cons...Can you guys (or anyone) recommend a good approach to generating unique and consistent identifiers for each cache macro in a single page (that would not be affected by page includes)? Its okay if the id's change on page edit, but short of that they should remain the same.
I've got a few ideas, but wanted to know if Atlassian had and recommended way.
Jan 24, 2006
Mike Cannon-Brookes says:
Jason - generating unique and consistent identifiers is hard, for a few reasons....Jason - generating unique and consistent identifiers is hard, for a few reasons. Firstly, the simplest way to generate unique identifiers is to add a value to the render context with each macro, which is then checked for and incremented if needed. This could simply be a counter, postfixed to the pagename or something like that.
The only problem I see with this strategy is that if someone edits the page and adds a new cache macro, you are in trouble. Previously cache regions 1, 2 and 3 now become regions 1, 2 and 4 (!) so the old cached content in the key for 3 will be wrong.
This may or may not be an issue though. Are all page edits going to flush the caches for a page? I would suggest that's a good idea. In which case, add an Event Listener to your plugin, listen for the PageUpdatedEvent and flush all your caches. This will mean that you can use a simple incremental scheme for numbering and should work AFAIK.
Jan 24, 2006
Bob Swift says:
We just need the counter, we can handle the other stuff. What do you mean "add ...We just need the counter, we can handle the other stuff. What do you mean "add a value to the render context". Maybe Jason knows what you mean, but I don't and I have some other macros to fix up with something similar. Thanks for helping!
Jan 24, 2006
Bob Swift says:
Never mind, Jason found the add/getParam. Do you guys know the dev kits java do...Never mind, Jason found the add/getParam. Do you guys know the dev kits java docs are incomplete/missing things (like RenderContext) for instance.
Jan 24, 2006
David Peterson [CustomWare] says:
Hey you're right! I hadn't noticed that addition before. Looking at the API docs...Hey you're right! I hadn't noticed that addition before. Looking at the API docs, it is a 2.0 addition, so if you use it the macro won't work prior to Confluence 2.0.
Jan 25, 2006
David Peterson [CustomWare] says:
As an adendum to this, the version of Utilities Plugin I just released (1.4.8/2....As an adendum to this, the version of Utilities Plugin I just released (1.4.8/2.0.2/2.1.2) has a new 'getContextParams()' method which uses the RenderContext.add/getParam methods in 2.0+ and fakes it with a Request Attribute in 1.4. This may be a reasonable way to get around the problem with 1.4, if you want to support that version of Confluence...
Jan 24, 2006
Jason Dillon says:
FYI, I'm only guessing that these methods will work as I think they will. Hopef...FYI, I'm only guessing that these methods will work as I think they will. Hopefully you can validate this for us with the updates to CacheMacro
Or maybe someone from Atlassian will tell us what's up.
Jan 24, 2006
Jason Dillon says:
Its not a problem when a page is added to add/remove cache macros, because when ...Its not a problem when a page is added to add/remove cache macros, because when the page commits the cache group for that page is flushed (or will be currently its not).
So, the page context that gets passed into the macro is the same for each page? Kinda like a page-level scope for attributes?
If so, that will work.
Jan 24, 2006
Jason Dillon says:
FYI, I think that we could use an event listener to handle the attachment checki...FYI, I think that we could use an event listener to handle the attachment checking/invalidation, which happens much less than page renders so it should speed things up.
I had thought about using an event listener to handle page change events, but not all pages have caches, and its simple enough to just do the version check invalidation in the macro.
Jul 17, 2006
Ryan Morgan says:
Great plugin! It also works with Could not retrieve RSS feed: no URL macros, ...Great plugin! It also works with
Aug 24, 2006
Scott Farquhar says:
Just a heads up that as of 2.3, the cache macro may need to be rewritten to hand...Just a heads up that as of 2.3, the cache macro may need to be rewritten to handle clustering.
Bob / Jason - you may want to contact Confluence support - you may need to use Confluence's cache manager for caching (which replicates across the cache), rather than just having an in-memory cache.
Cheers,
Scott