---
title: "Cache Macro"
canonical: "https://support.appfire.com/space/CACHE/66586270/Cache%20Macro"
format: markdown
---
> Macro (div)
> 
> ### On this page
> 
> > Macro (toc)

# Parameters

> Macro (table-plus)
> 
> | **Parameter** | **Default** | **Macro Browser Label** | **Description** |
> | --- | --- | --- | --- |
> | **id** | automatically generated | Reference id | Defaults to an automatically generated sequence number. The **id must be unique** on the page. Specifying the **id** can** improve performance** during edit by reducing cache refreshes during macro browser refresh, preview, and save cycle. It also helps when re-ordering cache macros on a page. The can be used when doing cache macro specific refreshes - see [**Cache Refresh**](#CacheMacro-refresh) below. Since 5.1.0. |
> | **refresh** | 1d<br>(one day) | Cache refresh period | Cache will be refreshed the next time page is viewed after the refresh period. A unqualified number will be treated as seconds. A number followed by one of the following characters will be treated as follows:<br>- **s** - seconds.
> - **m** - minutes.
> - **h** - hours.
> - **d**- days. |
> | **cron** |  | Cron expression | Cron-like expression for finer grained cache expiration and refresh. See [Cron Expressions](http://www.opensymphony.com/oscache/wiki/Cron%20Expressions.html). For example: 30 * * * * - cache will expire 30 minutes past each hour of the day. This means the data shown will |
> | **checkAttachments** | true | Check attachments | 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. |
> | **showRefresh** | false | Show refresh icon | When shown, the icon can be clicked to cause the immediate refresh of the data. |
> | **showDate** | false | Show date | Show the date and time of data was last generated. See also **dateFormat**. |
> | **index** | false | Index content | Add cached content to the Confluence search index. Whenever the cached data is updated, the page will be re-indexed. This enables external content to be found using Confluence search. |
> | **title** | Refresh | Title | Title to show when mouse is over the refresh icon. |
> | **dateFormat** | user date format | Date format | Defaults to the system defined format modified by the users time zone. The refresh date can be have a specific format. Use a [simple](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)[ ](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)[date](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)[ ](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html)[format](http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html) string. **Since 6.1.** |
> | **anchor** |  | Anchor | <span style="color: #707070">Name of a page anchor used to position after refresh link is pressed. Use @default to have an anchor generated at the macro location.</span><span style="color: #707070"> </span>**<span style="color: #707070">Since 6.7.</span>** |
> | **retry** | Default | Retry feature | Special handling for render errors that can be retried. See [Retry Feature](https://appfire.atlassian.net/wiki/spaces/CACHE/pages/66584623) for more details. **Since 6.8**. |

# Customization

- See [New Cache Management Options](https://appfire.atlassian.net/wiki/spaces/CACHE/pages/66584704).

# 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 Examples

- [How to index external content using the CACHE macro](https://appfire.atlassian.net/wiki/spaces/CACHE/pages/66586230)
- [How to index SQL data](https://appfire.atlassian.net/wiki/spaces/SQL/pages/74320280)
- [Site Statistics](http://confluence.atlassian.com/display/DISC/Site+Statistics)

# Tips and Techniques

- [Page display performance tips and techniques](https://appfire.atlassian.net/wiki/spaces/CACHE/pages/66590270)

# Compatibility With Other Macros

See [Interoperability](https://appfire.atlassian.net/wiki/spaces/CACHE/pages/66584627)

> Macro (anchor)



# Cache Refresh

- To force all cache macros on a page to refresh, use the **refresh** request attribute with value **true**
  - Example
- To force a specific cache macros on a page to refresh, use **refresh** request attribute with value equal to the cache macro **id**. If not specified, it defaults to a sequence number based on position on page
  - Example