-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance Caching Current Locale #5096
Performance Caching Current Locale #5096
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea to cache within the RequestScrope. From my side the code and documentation fits except of the small comment.
private static final String ATTRIBUTE_NAME = "RequestScopeCacheHelper"; | ||
|
||
@SuppressWarnings("unused") | ||
private static final Logger logger = LogManager.getLogger(RequestScopeCacheHelper.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this logger? If not then I suggest to remove it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not needed. Removed
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is no Logger anymore this imports are not needed anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had overlooked thx
Contributes to:
On many occasions, e.g., when translating messages, the method LocaleHelper.getCurrentLocale is called. If a user is logged in, this request will trigger a database query for the current language setting of the user, see Line 84. Naturally, issuing a database query for each
#{msgs.something}
will reduce performance significantly.In theory, this database query could be cached by Hibernate. Unfortunately, Hibernate caching is currently not working in Kitodo:
@org.hibernate.annotations.Cache
for each Bean, which are missing, see Documentation:Even with database caching enabled, one could argue that each
#{msgs.something}
should still not require a full re-evaluation of the Hibernate query framework. In my opinion, the current user locale should be cached in memory for each request.The proposed pull request caches
LocaleHelper.getCurrentLocale
via a simple request scoped cache implementation usingFacesContext
, meaning the cache is cleared after each HTTP request. Caching improves performance significantly (together with #5095):Drawbacks
Caching via
FacesContext
could be argued to not be a very clean way of implementing this. Ideally, such information should be cached via beans that are annotated with@RequestScope
. However, I'm not aware of any other way to introduce request scope to low-level static service methods like this. I suppose this is a JSF architectural design issue. Any suggestions are welcome.