简体   繁体   中英

Spring data - modifying queries and ehcache (cache)

Is it possible to make spring data modifying query such as:

@Modifying
@Query("update User u set u.firstname = ?1 where u.lastname = ?2")
int setFixedFirstnameFor(String firstname, String lastname);

Auto invalidate my ehcache of User entity?

Thanks!

Yes it is possible if you declare the User entity as cached using for example a READ_WRITE cache concurrency strategy:

@org.hibernate.annotations.Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class User {
    ...
}

In such case the cache invalidation will be taken care automatically by Hibernate.

Have a look at the Spring Cache abstraction documented here . It basically allows you to configure what to cache/evict where and completely configure which cache provider to be used in your application configuration.

Note, that this will cache on the annotated method level.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM