0

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.

4

1 回答 1

0

使这个工作出错的两个要点。他们是 :

  1. 在 Controller 中,我们使用注解@autowire,而在服务中,我们使用xml bean configuration. 所以两者都在创建不同的实例,这使它工作错误。

    解决方案:对于控制器,我们也以与服务相同的方式在 xml 中定义。

  2. 我们在 spring 中集成了 dwr (directwebremoting),但没有在 spring 的 DispatcherServlet 中集成,因此它可以工作但独立,因此服务实例也不同。

    解决方案:在 dwr 站点中定义的 DispatcherServlet 中集成 dwr 以与 springMVC 应用程序集成(我们已经做了另一种方式)

于 2015-01-12T15:55:23.753 回答