By default, boost sets one common expiry time for all the cached pages. Sometimes this may not be the best way to use static caching. A typical use-case is where it would be ok to cache older pages for longer periods of time because of the infrequent changes in content, comments or other activity associated with the page while it would be required to cache newer pages for much shorter periods of time.

As a site builder you can get control over this using the Boost Custom Expire Rules module which would allow you to set custom expiry times for different boost cached pages based on different rules.

The rules are configurable with JSON representation of the rule which you will have to hand code and add to the admin configuration. The formats of these JSON representation is very easy and examples given below should illustrate that.

The rules that are currently supported are given below. The module also has an API using which developers can add their own custom rules for setting the expiry times.

Node age based cache expire rule

Set custom expiry of boost cache based on creation date of the node. The rule supports open ended intervals from or to a given time and also closed intervals between two points in time. Time references are taken as seconds till now(). For example a time reference of 86400 defines a point in time which is 86400 seconds from now in the past which would be exactly 1 day before now().

Examples

  • {"name": "nodeage", "expire": 3600, "from": 86400, "to": 7200} - The rule sets an expiry of 1 hour for nodes that are between 1 day and 2 hours old
  • {"name": "nodeage", "expire": 86400, "to": 86400} - The rule sets an expiry of 1 day for nodes that are older than 1 day
  • {"name": "nodeage", "expire": 1200, "from": 7200} - The rule sets an expiry of 20 minutes for nodes that are younger than 2 hours

Node type based cache expire rule

Set custom expiry of boost cache based on type of the node. The rule supports setting different expire times for different content types.

Examples

  • {"name": "nodetype", "expire": 3600, "type": "story"} - The rule sets an expiry of 1 hour for story nodes
  • {"name": "nodetype", "expire": 86400, "type": "page"} - The rule sets an expiry of 86400 seconds (one day) for page nodes

Drupal path / URL based cache expire rule

Set custom expiry of boost cache based on drupal path. The rule supports setting different expire times for different patterns. The patters are the same as used in block configuration pages.

Examples

  • {"name": "path", "expire": 600, "path": "<front>"} - Set an expiry of 600 seconds for the home page
  • {"name": "path", "expire": 3600, "path": "taxonomy/term/*"} - Set an expiry of 3600 seconds for the taxonomy term pages
  • {"name": "path", "expire": 1200, "path": "categories/news"} - Set an expiry of 1200 seconds for the taxonomy term page with alias categories/news

Sample Configuration

{"name": "nodetype", "expire": 3000000, "type": "page"}
{"name": "nodeage", "expire": 700000, "to": 3000000}
{"name": "nodeage", "expire": 100000, "from": 3000000, "to": 700000}
{"name": "nodeage", "expire": 14400, "from": 700000, "to": 100000}
{"name": "nodeage", "expire": 3600, "from": 100000}
{"name": "path", "expire": 3600, "path": "taxonomy/term/*"}
{"name": "path", "expire": 3600, "path": "blog"}
{"name": "path", "expire": 1200, "path": "<front>"}

The above configuration does the following (after approximating 100000 as the number of seconds in a day)

  • Caches page content type for 30 days
  • Caches other content types based on the age of the node
  • Caches nodes older than 30 days for a week
  • Caches nodes older than 7 days but newer than 30 days for 1 day
  • Caches nodes older than 1 day but newer than 7 days to 4 hours
  • Caches nodes newer than a day to 1 hour
  • Caches taxonomy/term pages for 1 hour
  • Caches blog page for 1 hour
  • Caches front page for 20 minutes

Setting cron to clear expired pages

For the cache expiry times to work correctly there should be a cron job set with a time interval lower than the lowest expiry time you are setting using the rules. There would still be a variation of up to +cron_interval in the expiry times. Note that this is how boost cache flushing works in general.

Boost tag in cached pages

The module does not change the expiry time set in the boost tag inside cached pages but only changes the expiry times in the database (in Drupal 6) and in the file system (in Drupal 7). So do not be worried that the boost tag shows a different expiry time than what you expect.