Hi there,
I really like the new (and pretty simple) 3.1-version support for caches. However I think there's an important use case missing that I think is essential to make it usable:
Consider this scenario:
class Person (id , name)
I have two caches:
- A indexes by person.id
- B indexes by name
I have this service definition:
Code:/** Gets a person and chaches it in A by id */ @Cacheable(value={"A"}, key="#id") public Person get(Integer id) { /** Gets all people by name and chaches it in B by name */ @Cacheable(key="#name", value={"B"}) public Collection<Persona> buscarPersonas(String name) { /** Removes a person and removes all people from caches A and B */ @CacheEvict(value = {"A", "B"}, key= "#p.id", allEntries= true) public void removePerson(Person p) {...}
According to the doc, @CacheEvict will ignore the key and evict all registers from caches A and B.
That shouldn't work like that: There should be a way to say Delete only p.id from A and all registers form B
Why do we have to evict all registers from cache A after removing only one register from DB???
A solution could be modify @CacheEvict to allow multiple cache-eviction policies:
Someone from the Spring-Team could answer something about this?Code:/** Removes a person. Removes the cache instance of that person from cache A (keeping the other registers) Removes all registers from cache B @CacheEvict( { @EvictCfg(value = "A", key= "#p.id"), @EvictCfg(value = "B", allEntries= true)} ) public void removePerson(Person p) {...}
Regards!


Reply With Quote
