Add query parameter by updatedDate for _avatar image for cache control.

This commit is contained in:
KOUNOIKE Yuusuke
2017-03-14 05:36:02 +09:00
parent 3e4e278778
commit cdc8431865
2 changed files with 8 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ trait AvatarImageProvider { self: RequestCache =>
if(account.image.isEmpty && context.settings.gravatar){
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
} else {
s"""${context.path}/${account.userName}/_avatar"""
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
}
} getOrElse {
s"""${context.path}/_unknown/_avatar"""
@@ -31,7 +31,7 @@ trait AvatarImageProvider { self: RequestCache =>
if(account.image.isEmpty && context.settings.gravatar){
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
} else {
s"""${context.path}/${account.userName}/_avatar"""
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
}
} getOrElse {
if(context.settings.gravatar){
@@ -49,4 +49,4 @@ trait AvatarImageProvider { self: RequestCache =>
}
}
}
}

View File

@@ -74,6 +74,11 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
*/
def date(date: Date): String = new SimpleDateFormat("yyyy-MM-dd").format(date)
/**
* Format java.util.Date to "yyyyMMDDHHmmss" (for url hash ex. /some/path.css?19800101010203
*/
def hashDate(date: Date): String = new SimpleDateFormat("yyyyMMddHHmmss").format(date)
/**
* Returns singular if count is 1, otherwise plural.
* If plural is not specified, returns singular + "s" as plural.