Skip to content

Instantly share code, notes, and snippets.

@marcpalmer
Created September 5, 2011 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcpalmer/1195792 to your computer and use it in GitHub Desktop.
Save marcpalmer/1195792 to your computer and use it in GitHub Desktop.
Cache headers plugin example
withCacheHeaders {
etag {
"${content.ident()}:${content.version}".encodeAsSHA1()
}
lastModified {
(content.changedOn ?: content.createdOn)
}
generate {
def activeUser = wcmSecurityService.userName
request[REQUEST_ATTRIBUTE_USER] = activeUser
if (content) {
lastModified (content.changedOn ?: content.createdOn)
// 1 second caching, better than nothing
cache validFor: 1, shared:true
WcmContentController.showContent(this, content)
} else {
response.sendError 404, "No content found URI"
return null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment