Proper cache usage in Spring / Hibernate

前端 未结 1 1305
不思量自难忘°
不思量自难忘° 2021-01-22 01:52

Project X has the following parts:

a. Spring Data repository with separate methods like:

@Cacheable(value = \"xobjects\", unless = \"#result == null\")
X         


        
相关标签:
1条回答
  • 2021-01-22 02:04

    Your approach will either not work or will be very difficult to maintain. Besides the need for maintaining the cache manually, you would need to merge the entity instances back into each new Hibernate session (persistence context) if you want them to be managed, because the entities you return from your own cache will always be detached.

    The best approach is to use Hibernate second-level cache which will do cache entries lifecycle job for you automatically.

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