Results 1 to 3 of 3

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

  1. #1

    Default @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 at 01:52 PM.

  2. #2
    Join Date
    Mar 2009
    Posts
    18

    Default

    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 at 08:19 AM.

  3. #3
    Join Date
    Mar 2009
    Posts
    18

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •