Reputation: 47
I am trying to use ehcache in my java project, it's new for me.
now i am using ehcache for retrieving area list, and my project adding new area , that time i am using @TriggersRemove functionality for once clear the cache and then reload it.
ex: i have retrive 10 areas and using ehcache , and i adding one more area that time i clear the cache and reload it.
is any other options for avoiding the data reload in cache.
my code:
@Cacheable(cacheName="retrieveAreas")
public List<AreaBO> retrieveAreas(){
//some code here
}
@TriggersRemove(cacheName="retrieveAreas", removeAll=true)
public long addArea(AreaBO areaBO) throws UserServiceException{
// some codes here
}
Upvotes: 0
Views: 490
Reputation: 64039
It seems that you are using the annotation from EhCache. If you where to switch to the caching annotations provided by Spring since version 3.1 your code would be:
@Cacheable(value="retrieveAreas")
public List<AreaBO> retrieveAreas(){
//some code here
}
@CachePut(value="retrieveAreas")
public long addArea(AreaBO areaBO) throws UserServiceException{
// some codes here
}
The difference as you can see is in the @CachePut annotation that adds the return value of the method to the cache specified. I am not aware of a corresponding annotation in EHCache
Upvotes: 1