1. First level Cache--Session.

Querying of same object multiple times within a same session will only call DB for once, the rest of times will use cache to retrieve.

Same to openSession()&getCurrentSession()

2. Second level Cache--SessionFactory.

Data that is good for second level cache:

1.limited set of data;

2. Rarely being modified;

3. Won't be access by multiple objects at the same time

Example:

user authorization info. User entries are limited. load()&iterative() use secondary cache; list uses second level cache,however, query doesn't!!

When hibernate accesses data, it first check first level cache, then check second level cache if it's configured, then check DB.

Configuration:

1.add ehcache.xml

2.

<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class"> org.hibernate.cache.ehcache.EhCacheRegionFactory</property>

3. @Cache(usage = CacheConcurrencyStrategy.READ_WRITE) ----> use default cache

For query checking using second level:

<property name="cache.use_query_cache">true</property>

xx.createQuery().setCachable(true).list

优质内容筛选与推荐>>
1、Calendar获取第二天时间
2、Win10无线网络配置VMware的nat网络
3、Extjs常用的控件
4、时间格式设置
5、listview某一项不可点击


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号