调用@CacheEvict 注解

Invocation of @CacheEvict annotation

我知道@CacheEvict 对Spring.I中的缓存数据执行清理操作只是想了解::

如果我用 @CacheEvict 注释一个方法,它会像 @PreDestroy 注释一样自动调用 JSF.i.e 在 bean 对象被垃圾收集时吗?

@CacheEvict 不像 @PreDestroy;它不会自动调用。

作为 documentation describes, @CacheEvict is evaluated anytime an @CacheEvict annotated bean method is invoked. You can conditionally control when the eviction actually occurs, along with whether the eviction occurs before the method executes or after (the default), using the @CacheEviction annotation, beforeInvocation attribute,以及控制其他设置。

Spring 对 @CacheEvict 的声明性配置也与 JVM 垃圾收集无关。通常,您需要依赖各个缓存提供程序(例如 ehcache、memcached)或更高级的提供程序(例如 Apache Geode、Hazelcast 或 Redis)的功能来配置、调整和控制 JVM 级别的逐出触发器和操作.

每个提供商在这方面可能具有相似和不同的能力。

希望对您有所帮助。