How to cache complex calulations in a wicket web application
I am building a wicket web application. It shows a list of 'entities' with a DataView
and also displaying a details page which wo开发者_JAVA百科rks fine. Only the needed rows from the database are loaded into my DataView
, so performance is good.
I can also show a calculated value on the details page, which is generated on the fly from the 'entity'. But when i want to sum up this calculated value on my list page, performance gets poor when there are several hundreds of rows in the table. This is because the value is generated for the whole table for every session.
Should i cache this calculated value (if yes, how can i do this) or would it be better to add a column in my database table that holds this value, which would violate the DRY principle?
As @biziclop commented, a solution for a simple cache is adding a field to the Application Class, which caches the calculated value. This way, the calculations must be made on application startup and on every change of relevant data.
精彩评论