In spring application we have two controllers i.e. controller1, controller2 and one services i.e. service1
i want to use method caching and for that i have configured spring cache.
i am caching method named method1 in service1 with @Cacheable(value = "cache1")
and for removing cache i am using @CacheEvict(value = "cache1", allEntries = true)
on another method named method2 in service1.
so caching works fine but evicting not working as i want.
so if i call method1 (cachable method) from controller1 it will cache and call method2 (cacheEvict method) from controller1 then it will remove / evict cachce properly BUT when i call method2 (cacheEvict method) from controller2 then it is NOT REMOVING / EVICTING CACHE but I WANT IT TO DO.
I want to evict / remove the cache every time the method get called doesn't matter from which controller it get called.
this is required in most cases because controller1 is for customer and controller2 is for admin. we cache methods used in controller1 and we want to remove the same cache when any update happens from controller2 i.e. admin.
Two main points that make this works wrong. They are :
In Controller we are using annotation @autowire
and in services we are using xml bean configuration
. so both are creating different instance and it makes it works wrong.
Solution : for controller also we have defined in xml the same way we do for services.
we integrated dwr (directwebremoting) in spring but not in spring's DispatcherServlet so it works but independently so for that also services instance are different.
Solution : Integrated dwr inside DispatcherServlet as definded in dwr site to integrate with springMVC application (we have done another way)