What's difference between hibernate caching and Spring framework cache?

前端 未结 2 1360
感情败类
感情败类 2021-02-16 00:04

I have an application where I get the data from database (using hibernate). I want to load the cache (per user) with database state once per day and use the cache instead.

相关标签:
2条回答
  • 2021-02-16 00:18

    Starting with Hibernate cache is a more prudent decision in my view, especially because the two don't exclude each other. In terms of performance Spring cache can offer you more, its much higher in the stack, you can cache business results (basically more than you can with hibernate's second level cache).

    However one outstanding distinction is clearing the cache. With Spring cache you need to clear explicitly, while the hibernate cache is maintained automatically if your inserts, updates and deletions go through hibernate's framework.

    In the context of the projects that I'm involved, using hibernate's second level cache is assumed, a default almost. Spring cache we use for the data that are much more static in nature.

    0 讨论(0)
  • 2021-02-16 00:40

    Hibernate has 2 levels of cache. 1. First level 2. Second level

    Second level chache is for the whole application and first level cache is for the current hibernate session. There is no cache available per user basis.

    Also if you are using spring managed beans + caching. There is a provision for you to cache the beans for entire application rather than for a user. (little uncertain on this)

    It sounds to me that you want to store the data in the user's session. ie., as long as the user is having an active session. Spring has a session scoped beans you may want to use these to cache the data per user.

    0 讨论(0)
提交回复
热议问题