Example usage for org.hibernate Cache evictQueryRegion

List of usage examples for org.hibernate Cache evictQueryRegion

Introduction

In this page you can find the example usage for org.hibernate Cache evictQueryRegion.

Prototype

void evictQueryRegion(String regionName);

Source Link

Document

Evicts all cached query results under the given name.

Usage

From source file:com.daphne.es.monitor.web.controller.HibernateCacheMonitorController.java

License:Apache License

@RequestMapping(value = "/evictQuery")
@ResponseBody/*  w w w.ja  va2s. com*/
public String evictQuery(@RequestParam(value = "queries", required = false) String[] queries) {

    boolean queriesEmpty = ArrayUtils.isEmpty(queries);

    Cache cache = HibernateUtils.getCache(em);

    if (queriesEmpty) {
        cache.evictQueryRegions();
        cache.evictDefaultQueryRegion();
    } else {
        for (String query : queries) {
            cache.evictQueryRegion(query);
        }
    }

    return "??";
}

From source file:nl.strohalm.cyclos.dao.BaseDAOImpl.java

License:Open Source License

/**
 * Evicts all second-level cache elements which could get stale on entity updates
 *//*from w  ww  .  j av  a2s  . c o m*/
protected void evictSecondLevelCache() {
    final SessionFactory sessionFactory = getSessionFactory();

    // If this DAO is cached, evict the collection regions, as we don't know which ones will point out to it
    if (hasCache) {
        synchronized (sessionFactory) {
            final Cache cache = sessionFactory.getCache();
            // We must invalidate all collection regions, as we don't know which other entities have many-to-many relationships with this one
            cache.evictCollectionRegions();
        }
    }

    // Evict the query cache region
    if (queryCacheRegion != null) {
        synchronized (sessionFactory) {
            final Cache cache = sessionFactory.getCache();
            cache.evictQueryRegion(queryCacheRegion);
        }
    }
}