现在的位置: 首页 > 综合 > 正文

shop++的缓存配置

2013年03月12日 ⁄ 综合 ⁄ 共 1391字 ⁄ 字号 评论关闭

 

shop++的缓存配置

默认的shop++开源版本只有 部分查询缓存。

shop++应用可采用oscache作为Hibernate的缓存配置,为常见的缓存策略应用。
实体缓存(entity cache)、实体集合缓存(collectioncache)和查询缓存(query cache)通过Java annotations实现,所以更改缓存后需要重新编译发布。
1.1.  缓存的配置文件
1.1.1.  applicatonContext.xml

以下两处设置为true
[font=&quot][font=&quot]

引用

[font=&quot]<!-- 是否开启二级缓存[font=&quot]-->[font=&quot][font=&quot]hibernate.cache.use_second_level_cache=true
[font=&quot][font=&quot]<!-- 是否开启查询缓存[font=&quot]-->[font=&quot][font=&quot]hibernate.cache.use_query_cache=true

1.1.2.  oscache.properties
依据应用服务器的内存设置缓存对象的个数,默认为10000
cache.capacity=10000
1.2.  缓存种类
1.2.1.  实体缓存

针对不同实体的作用,选择合适的缓存策略。
例如Product、ProductAttribute选择READ_WRITE

引用

@Entity
@Searchable
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
publicclass
Product extendsBaseEntity {

ProductCategory、Navigation选择NONSTRICT_READ_WRITE

引用

@Entity
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
publicclass
NavigationextendsBaseEntity {

1.2.2.  实体的集合缓存
例如,配置Product实体的规格参数属性的缓存。

引用

@CollectionOfElements
@MapKey(targetElement= ProductAttribute.class)
@LazyCollection(LazyCollectionOption.FALSE)
@Cascade(value= { CascadeType.DELETE})
@Cache(usage= CacheConcurrencyStrategy.READ_WRITE)
public
Map<ProductAttribute,String> getProductAttributeMapSto() {
returnproductAttributeMapStore;
}

1.2.3.  查询缓存
默认的shop++开源版本
例如,在ProductCategoryServiceImpl配置查询缓存。

引用

    @Cacheable(modelId= "caching")
    publicList getParentProductCategoryList(ProductCategoryproductCategory) {

 

抱歉!评论已关闭.