When and how to use hibernate second level cache?

前端 未结 4 1302
旧巷少年郎
旧巷少年郎 2020-12-02 04:04

I have trouble understanding when hibernate hits the second level cache and when does it invalidate the cache.

This is what I currently understand:

  • Sec
4条回答
  •  悲哀的现实
    2020-12-02 04:58

    • the 2nd level cache is a key-value store. It only works if you get your entities by id
    • the 2nd level cache is invalidated / updated per entity when an entity is updated/deleted via hibernate. It is not invalidated if the database is updated in a different way.
    • for queries (e.g. list of customers) use the query cache.

    In reality it is useful to have a key-value distributed cache - that's what memcached is, and it powers facebook, twitter and many more. But if you don't have lookups by id, then it won't be very useful.

提交回复
热议问题