页面上有好多数据是重复使用,往freemarker标签中填充数据,是比较大的一个性能瓶颈,所以项目中使用freemarker的BeanWrapper cache.
使用方法
修改文件
1、sturts.properties 增加struts.freemarker.beanwrapperCache=true
Code
#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager
struts.freemarker.wrapper.altMap=true
struts.freemarker.beanwrapperCache=true
2、FreemarkerManager(org.apache.struts2.views.freemarker)
Code
private boolean altMapWrapper;
private boolean cacheBeanWrapper;
private Map<String,TagLibrary> tagLibraries;
@Inject(StrutsConstants.STRUTS_I18N_ENCODING)
Line 137
altMapWrapper = "true".equals(val);
}
@Inject(StrutsConstants.STRUTS_FREEMARKER_BEANWRAPPER_CACHE)
public void setCacheBeanWrapper(String val) {
cacheBeanWrapper = "true".equals(val);
}
@Inject
public void setContainer(Container container) {
Map<String,TagLibrary> map = new HashMap<String,TagLibrary>();
Line 242
}
protected BeansWrapper getObjectWrapper() {
StrutsBeanWrapper wrapper = new StrutsBeanWrapper(altMapWrapper);
wrapper.setUseCache(cacheBeanWrapper);
return wrapper;
}
3、StrutsConstants(org.apache.struts2)增加STRUTS_FREEMARKER_BEANWRAPPER_CACHE
Code
/** Cache model instances at BeanWrapper level */
public static final String STRUTS_FREEMARKER_BEANWRAPPER_CACHE = "struts.freemarker.beanwrapperCache";
修改后,页面中重复数据会从cache 获取,提升 页面性能