Announcement Announcement Module
Collapse
No announcement yet.
Spring @Cacheable with multiple caches.. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring @Cacheable with multiple caches..

    If I have a service:

    Code:
    public PersonServiceImpl {
       public getPerson(int id){ //Method #1
          ...
       }
       public getPersonByName(String name) { //Method #2
          ...
       }
       public deletePerson(int id) { //Method #3
          ...
       }
       public deletePersonByName(String name) { //Method #4
          ...
       }
       public deletePerson(Person person) { //Method #5
          ...
       }
    }
    Presume that both id and name are unique for the person table. Can I have 2 caches
    Code:
    @Cacheable(value="personsById")
    @Cacheable(value="personsByName")
    both of which update when Methods #1 OR #2 are called? personsById is a map of id --> Person, whereas personsByName is a map of name --> Person.

    Is it possible to @CacheEvict exactly 1 (relevant) item from each of these Caches whenever Method #5 is called? (Since the whole Person object is provided, the id as well as the name are available)

    When Method #3 is called, we can evict the single relevant item from personsById, but we'll have to evict the entire of personsByName. Is it even possible to work 2 caches in this fashion?
    When Method #4 is called, we can evict the single relevant item from personsByName, but we'll have to evict the entire of personsById. Is that even possible to work 2 different caches in this fashion?

    Basically Im asking if it's possible to work with 2 separate caches in your caching and eviction?
Working...
X