shop++的缓存配置

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
ProductextendsBaseEntity {



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) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值