Announcement Announcement Module
Collapse
No announcement yet.
@CacheEvict incomplete functionality Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @CacheEvict incomplete functionality

    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:

    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) {...}
    Someone from the Spring-Team could answer something about this?

    Regards!
    Last edited by spring-like-jose; Sep 19th, 2011, 05:42 AM.

  • #2
    Gotta agree.

    I'd like to do something like this:
    Code:
    @Cacheable(value="clientCache" key="#clientid")
    public Client getClient(Long clientid);
    
    @Cacheable(value="clientListCache")
    public List<Client> getAllClients();
    
    @CacheEvictList({
      @CacheEvict(value="clientCache", key="#client.id"),
      @CacheEvict(value="clientListCache", allEntries=true)
    })
    public Client save(Client client);
    Any chance we could get a feature like that? I'd hate to have to blast away my ENTIRE clientCache just because I save one.

    There's other things I can do, so it's not the end of the world, but seems to make sense that if I'm going to be able to invalidate multiple caches, I should be able to specify different options for each cache.

    Comment


    • #3
      I agree. What is your workaround Falken224?
      Is there any insight from the Spring team?

      Comment

      Working...
      X