Performance 干净会话和最小数据库访问之间的更好方式
考虑以下场景:我有一个bean,它处理用户搜索,并在具有不同URL的许多页面上使用大量参数。许多用户可能会花更多的时间进行自定义搜索,目前我每次都会点击数据库来加载这些静态列表Performance 干净会话和最小数据库访问之间的更好方式,performance,session,jsf,caching,cookies,Performance,Session,Jsf,Caching,Cookies,考虑以下场景:我有一个bean,它处理用户搜索,并在具有不同URL的许多页面上使用大量参数。许多用户可能会花更多的时间进行自定义搜索,目前我每次都会点击数据库来加载这些静态列表 @ManagedBean @ViewScoped public class SearchBean extends DefaultBean { private String searchPath; //seo: build a url-friendly path depending on search-parameter
@ManagedBean
@ViewScoped
public class SearchBean extends DefaultBean {
private String searchPath; //seo: build a url-friendly path depending on search-parameters
private List<Currency>currencies;
private List<Country>countries;
private List<Market>markets;
private List<DrugTypes>drugTypes;
private List<Products>products;
/**
* ...15 other lists
*/
private List<ResultData>results;
@PostConstruct
public void init(){
this.currencies = Currency.getAll(); //jpa-entities
this.countries = Country.getAll();
this.markets = Markets.getAll();
this.drugTypes = DrugTypes.getAll();
this.products = Products.getAll();
}
public String search(){
this.results = ResultData.getByParameters(getSearchParams());
//
//e.g. localhost:8080/myApp/search/markets/germany/class-alpha-products/rhesus?faces-redirect=true
return searchPath;
}
public List<Currency> getCurrencies() { return currencies; }
public void setCurrencies(List<Currency> currencies) { this.currencies = currencies; }
public List<Country> getCountries() { return countries; }
public void setCountries(List<Country> countries) { this.countries = countries; }
public void setMarkets(List<Market> markets) { this.markets = markets; }
public List<Market> getMarkets() { return markets; }
public void setDrugTypes(List<DrugTypes> drugTypes) { this.drugTypes = drugTypes; }
public List<DrugTypes> getDrugTypes() { return drugTypes; }
public List<Products> getProducts() { return products; }
public void setProducts(List<Products> products) { this.products = products; }
}
@ManagedBean
@视域
公共类SearchBean扩展了DefaultBean{
私有字符串searchPath;//seo:根据搜索参数构建url友好路径
私人货币;
私营国家;
私人市场;
私有类型;
私人产品;
/**
*…15份其他名单
*/
私有列表结果;
@施工后
公共void init(){
this.currences=Currency.getAll();//jpa实体
this.countries=Country.getAll();
this.markets=markets.getAll();
this.drugTypes=drugTypes.getAll();
this.products=products.getAll();
}
公共字符串搜索(){
this.results=ResultData.getByParameters(getSearchParams());
//
//e、 g.本地主机:8080/myApp/search/markets/germany/class alpha products/rhesus?faces redirect=true
返回搜索路径;
}
公共列表GetCurrences(){返回货币;}
public void setcurrences(列出货币){this.currences=currences;}
公共列表getCountries(){return countries;}
公共国家(列出国家){this.countries=countries;}
公共市场(列出市场){this.markets=markets;}
公共列表getMarkets(){return markets;}
public void setDrugTypes(列出drugTypes){this.drugTypes=drugTypes;}
public List getDrugTypes(){return drugTypes;}
public List getProducts(){return products;}
public void setProducts(列出产品){this.products=products;}
}
关于标题,推荐的方式是什么?我的小抱怨是,我在控制台上看到了20个jpa查询,尽管在客户端使用
构建的列表数据在新页面上没有变化,但必须包含在每个子页面上
感谢收看!没什么。缓存数据库实体不是前端(UI)框架的责任。这是持久性(DB)框架的责任,因此在您的案例中是JPA JPA提供了二级缓存的可能性。与您的所有方案相比,主要优势在于它准确地知道哪些实体更容易查询,因此需要缓存,以及何时由于实体更改而使缓存的实体失效。JSF是一个基于HTML表单的愚蠢MVC框架,它只代表我们业务服务的er接口事件/数据对此一无所知 另见: