Announcement Announcement Module
Collapse
No announcement yet.
@CacheEvict not working when there's @Cacheable in the same class? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @CacheEvict not working when there's @Cacheable in the same class?

    Hello,

    I have two methods in my class like this:
    Code:
    @Cacheable("mycache")
    @Transactional(readOnly = true)
    public SearchResultDTO<PromotionDTO> getPromotions(int startIndex, int pageSize, ....){
        .....
    }
    
    @CacheEvict(value = "mycache", allEntries = true)
    @Transactional(readOnly = false)
    public void deletePromotion(String applicationId, Long promotionId) {
        .....
    }
    When I start the app, the SpringCacheAnnotationParser parser is never called to process the CacheEvict annotation (method: public Collection<CacheOperation> parseCacheAnnotations(AnnotatedElement ae) )

    If I change my code and remove the Cacheable annotation, the parser processes the CacheEvict annotation properly.

    Is this a bug or a framework restriction?

    Regards,
    Juan
    Last edited by juanmanuel32; Jul 15th, 2012, 02:52 PM.

  • #2
    Hi,

    I have the same problem. Did you (or anyone) find out, what is/was the problem or what to do (except of putting it into another class)?

    Annotations are in the implementation of an interface... both are public...

    Spring 3.1.2

    Code:
    @Override
    	@CacheEvict(value="accessMap", allEntries=true)
    	public void resetAccessMap()
    	{
    		LOG....
    	}
    	
    	@Override
    	@Cacheable(value="accessMap")
    	public Collection<String> getAccessMap(Role role)
    Thanks in advance!
    mala
    Last edited by langmar; Jul 26th, 2012, 09:19 AM.

    Comment


    • #3
      sorry for spamming - found the answer to my question here:

      http://stackoverflow.com/a/10347208

      "In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual caching at runtime even if the invoked method is marked with @Cacheable - considering using the aspectj mode in this case."

      mala

      Comment

      Working...
      X