简体   繁体   中英

Force clear EJB3 cache in Glassfish

I have application written in Java that is using EJB3 + Toplink. I'm using Glassfish as my app. server.

Sometimes the data that has been cached is old and I need to clear my cache manually. I know that we can set time to clear it, but I would like to make a button that will manually clear it for me. Is is possible to do?

Apparently you can refresh cache with you query your database using this code:

Query query = em.createQuery(sql.toString()).setHint("toplink.refresh", "true");

This works for me.

I think it is better to use:

em.createNamedQuery("findAll").setHint(QueryHints.CACHE_RETRIEVE_MODE, CacheRetrieveMode.BYPASS).getResultList();

it works for me and I think it is more standard way.

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