Announcement Announcement Module
Collapse
No announcement yet.
Spring 3.1 Cache Abstraction : expired element return null Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3.1 Cache Abstraction : expired element return null

    Hi,

    I have an application which use Spring 3.1.0.M1 and cache abstraction using ehcache and @Cacheable annotation.

    I configured my cache as :
    Code:
    <cache 	name="ldap_cache"
    			maxElementsInMemory="10000"
    			eternal="false"
    			overflowToDisk="false"
    			timeToIdleSeconds="120"
    			timeToLiveSeconds="480"
    	/>
    I have two classes LdapProxyManager and LdapManager. When I call LdapProxyManager.findFromDn(myDn) for the first times, it is working, and the object is put in the cache.
    When I call another time the LdapProxyManager.findFromDn(myDn), the results of the LdapManager.findFromDn(myDn) are taken from the cache.

    Now I wait for a while... wait for the element in cache to be expired...

    I call the LdapProxyManager.findFromDn(myDn), he results of the LdapManager.findFromDn(myDn) are taken from the cache, but it return null.

    What can I do in order the result not to be taken from the cache when expired ?

    Code:
    public class LdapProxyManagerImpl implements LdapProxyManager {
    
    	@Autowired LdapManager ldapMgr;
    	
    	@Override
    	public BaseEntity findFromDn(String dn) {
    		return ldapMgr.findFromDn(dn);
    	}
    }
    Code:
    public class LdapManagerImpl implements LdapManager {
    
    	private static final String CACHE_NAME = "ldap_cache";
    	private LdapProvider ldap;
    
    	@Override
    	@Cacheable(CACHE_NAME)
    	public BaseEntity findFromDn(String dn) {
    		try {
    			logger.debug("findFromDn(" + dn + ")");
    			return ldap.findFromDn(dn);
    		} catch (Exception e) {
    			return null;
    		}
    	}
    }
    Last edited by blink38; May 26th, 2011, 04:33 AM.

  • #2
    The solution

    in fact, I found the solution :

    https://jira.springsource.org/browse/SPR-8023

    It was a bug resolved in 3.1 M2

    Comment

    Working...
    X