How to add cache feature in Spring Data JPA CRUDRepository

后端 未结 4 727
半阙折子戏
半阙折子戏 2020-12-31 04:27

I want to add \"Cacheable\" annotation in findOne method, and evict the cache when delete or happen methods happened.

How can I do that ?

4条回答
  •  悲哀的现实
    2020-12-31 05:24

    Try provide MyCRUDRepository (an interface and an implementation) as explained here: Adding custom behaviour to all repositories. Then you can override and add annotations for these methods:

    findOne(ID id)
    delete(T entity)
    delete(Iterable entities)
    deleteAll() 
    delete(ID id) 
    

提交回复
热议问题