Skip to content
Browse files

Memoize the value of a resource lookup for the duration of the request.

Closes #1372
  • Loading branch information...
1 parent d35132a commit 0ffc21c762e024ba92eb2c8d30aa9c758baf92bb @jeppenejsum jeppenejsum committed with fmpwizard
Showing with 7 additions and 11 deletions.
  1. +7 −11 web/webkit/src/main/scala/net/liftweb/http/S.scala
View
18 web/webkit/src/main/scala/net/liftweb/http/S.scala
@@ -933,18 +933,10 @@ trait S extends HasParams with Loggable {
* If you do not define an entry for a particular key, we fall back to using
* Lift's core entries.
*
- * We cache the values in modes other than DevMode
- *
* @see LiftRules.resourceNames
* @see LiftRules.resourceBundleFactories
*/
- def _resourceBundles: List[ResourceBundle] = resourceBundles(locale) ++ liftCoreResourceBundle.toList
-
- private lazy val cachedResourceBundles = _resourceBundles
-
- private def resourceBundles: List[ResourceBundle] =
- if (Props.devMode) _resourceBundles else cachedResourceBundles
-
+ def resourceBundles: List[ResourceBundle] = resourceBundles(locale) ++ liftCoreResourceBundle.toList
def resourceBundles(loc: Locale): List[ResourceBundle] = {
_resBundle.box match {
@@ -985,6 +977,9 @@ trait S extends HasParams with Loggable {
*/
def liftCoreResourceBundle: Box[ResourceBundle] = _liftCoreResBundle.is
+
+ private object resourceValueCache extends TransientRequestMemoize[(String, Locale), String]
+
/**
* Get a localized string or return the original string.
* We first try your own bundle resources, if that fails, we try
@@ -996,7 +991,7 @@ trait S extends HasParams with Loggable {
*
* @see # resourceBundles
*/
- def ?(str: String): String = ?!(str, resourceBundles)
+ def ?(str: String): String = resourceValueCache.get(str -> locale, ?!(str, resourceBundles))
/**
* Get a localized string or return the original string.
@@ -1011,7 +1006,8 @@ trait S extends HasParams with Loggable {
*
* @see # resourceBundles
*/
- def ?(str: String, locale: Locale): String = ?!(str, resourceBundles(locale))
+ def ?(str: String, locale: Locale): String = resourceValueCache.get(str -> locale, ?!(str, resourceBundles(locale)))
+
/**
* Attempt to localize and then format the given string. This uses the String.format method
* to format the localized string.

0 comments on commit 0ffc21c

Please sign in to comment.
Something went wrong with that request. Please try again.