Package net.sf.ehcache

Examples of net.sf.ehcache.CacheManager


    private void processSettings (HttpServletRequest request,
                                  HttpServletResponse response,
                                  HttpSession session)
            throws IOException, ServletException {

        CacheManager ehcacheManager = ((EhCacheProvider) SpringContextSingleton.getBean("ehCacheProvider")).getCacheManager();
       
        if (request.getParameter ("flushAllCaches") != null) {
            CacheHelper.flushAllCaches();
        } else if (request.getParameter ("flushOutputCaches") != null) {
            CacheHelper.flushOutputCaches();
        } else if (request.getParameter ("flushHibernateCaches") != null) {
            CacheHelper.flushHibernateCaches();
        }

        // get the cache factory instance
        CacheService cacheFactory = ServicesRegistry.getInstance().getCacheService();

        // get the registered cache names
        Iterator cacheNameIte = cacheFactory.getNames ().iterator();

        // for each cache..
        while (cacheNameIte.hasNext()) {

            // get the cache name
            String curCacheName = (String)cacheNameIte.next ();

            if (request.getParameter ("flush_" + curCacheName) != null) {
                Cache cache = ServicesRegistry.getInstance().getCacheService().getCache (curCacheName);
                if (cache != null) {
                    logger.info("Flushing cache: " + curCacheName);
                    cache.flush(false);
                }
            }
        }
       
        for (String cacheName : ehcacheManager.getCacheNames()) {
            if (request.getParameter ("flush_ehcache_" + cacheName) != null) {
                net.sf.ehcache.Cache cache = ehcacheManager.getCache(cacheName);
                if (cache != null) {
                    logger.info("Flushing cache: " + cacheName);
                    // flush without notifying the other cluster nodes
                    cache.removeAll(true);
                    // reset statistics
View Full Code Here


     * @param propagateInCluster
     *            if set to true the flush is propagated to other cluster nodes
     */
    public static void flushAllCaches(boolean propagateInCluster) {
        logger.info("Flushing all caches");
        CacheManager ehcacheManager = getEhcacheManager();
        CacheService cacheService = ServicesRegistry.getInstance().getCacheService();

        // legacy caches
        Iterator<String> cacheNames = cacheService.getNames().iterator();
        while (cacheNames.hasNext()) {
            String curCacheName = cacheNames.next();
            org.jahia.services.cache.Cache<Object, Object> cache = cacheService
                    .getCache(curCacheName);
            if (cache != null) {
                cache.flush(propagateInCluster);
            }
        }

        // Ehcaches
        for (String cacheName : ehcacheManager.getCacheNames()) {
            Cache cache = ehcacheManager.getCache(cacheName);
            if (cache != null) {
                // flush
                cache.removeAll(!propagateInCluster);
                // reset statistics
                cache.clearStatistics();
View Full Code Here

     * @param propagateInCluster
     *            if set to true the flush is propagated to other cluster nodes
     */
    public static void flushEhcacheByName(String cacheName, boolean propagateInCluster) {
        logger.info("Flushing {}", cacheName);
        CacheManager ehcacheManager = getEhcacheManager();
        Cache cache = ehcacheManager.getCache(cacheName);
        if (cache != null) {
            // flush
            cache.removeAll(!propagateInCluster);
            // reset statistics
            cache.clearStatistics();
View Full Code Here

     * @param propagateInCluster
     *            if set to true the flush is propagated to other cluster nodes
     */
    public static void flushOutputCaches(boolean propagateInCluster) {
        logger.info("Flushing HTML output caches");
        CacheManager ehcacheManager = getEhcacheManager();
        for (String cacheName : ehcacheManager.getCacheNames()) {
            if (!cacheName.startsWith("HTML")) {
                continue;
            }
            Cache cache = ehcacheManager.getCache(cacheName);
            if (cache != null) {
                // flush
                cache.removeAll(!propagateInCluster);
                // reset statistics
                cache.clearStatistics();
View Full Code Here

  @Inject
  public EhCacheCacheProvider(@Named("shindig.cache.ehcache.config") String configPath,
                              @Named("shindig.cache.ehcache.jmx.enabled") boolean jmxEnabled,
                              @Named("shindig.cache.ehcache.jmx.stats") boolean withCacheStats)
      throws IOException {
    cacheManager = new CacheManager(getConfiguration(configPath));
    create(jmxEnabled, withCacheStats);
  }
View Full Code Here

         */
        @Override
        protected Cache createInternal(String name, Object... args) {
            final Cache cache;
           
            final CacheManager cacheManager = EhCacheFacade.this.cacheManager;
            final Log logger = EhCacheFacade.this.logger;

            try {
                if (cacheManager.cacheExists(name)) {
                    cache = cacheManager.getCache(name);
                   
                    if (logger.isDebugEnabled()) {
                        logger.debug("Using existing EhCache for '" + name + "'");
                    }
                }
                else if (EhCacheFacade.this.createMissingCaches) {
                    cacheManager.addCache(name);
                    cache = cacheManager.getCache(name);
                   
                    if (logger.isWarnEnabled()) {
                        logger.warn("Created new default EhCache for '" + name + "'");
                    }
                }
View Full Code Here

     *
     * @throws Exception in the event of misconfiguration (such as failure to
     *             set an essential property) or if initialization fails.
     */
    public void afterPropertiesSet() throws Exception {
        CacheManager cacheManager = cacheProvider.getCacheManager();
        blockingCache = cacheManager.getCache(CACHE_NAME);
        if (blockingCache == null) {
            cacheManager.addCache(CACHE_NAME);
            blockingCache = cacheManager.getCache(CACHE_NAME);
//          blockingCache.setTimeoutMillis(blockingTimeout);
        }
        blockingCache.setStatisticsEnabled(cacheProvider.isStatisticsEnabled());
       
        dependenciesCache = cacheManager.getCache(DEPS_CACHE_NAME);
        if (dependenciesCache == null) {
            cacheManager.addCache(DEPS_CACHE_NAME);
            dependenciesCache = cacheManager.getCache(DEPS_CACHE_NAME);
        }
        dependenciesCache.setStatisticsEnabled(cacheProvider.isStatisticsEnabled());
       
        regexpDependenciesCache = cacheManager.getCache(REGEXPDEPS_CACHE_NAME);
        if (regexpDependenciesCache == null) {
          cacheManager.addCache(REGEXPDEPS_CACHE_NAME);
            regexpDependenciesCache = cacheManager.getCache(REGEXPDEPS_CACHE_NAME);
        }
        regexpDependenciesCache.setStatisticsEnabled(cacheProvider.isStatisticsEnabled());
    }
View Full Code Here

     *
     * @throws Exception in the event of misconfiguration (such
     *                   as failure to set an essential property) or if initialization fails.
     */
    public void afterPropertiesSet() throws Exception {
        CacheManager cacheManager = cacheProvider.getCacheManager();
        cache = cacheManager.getCache(CACHE_NAME);
        if (cache == null) {
            cacheManager.addCache(CACHE_NAME);
            cache = cacheManager.getCache(CACHE_NAME);
        }
        cache.setStatisticsEnabled(cacheProvider.isStatisticsEnabled());

        permissionCache = cacheManager.getCache(PROPERTY_CACHE_NAME);
        if (permissionCache == null) {
            cacheManager.addCache(PROPERTY_CACHE_NAME);
            permissionCache = cacheManager.getCache(PROPERTY_CACHE_NAME);
        }
        permissionCache.setStatisticsEnabled(cacheProvider.isStatisticsEnabled());
    }
View Full Code Here

                                ", total hits=" + curCache.getTotalHits() + ", efficiency=" + efficiencyStr + "%");
                    }
                }
   
                // Ehcaches
                CacheManager ehcacheManager = ((EhCacheProvider) SpringContextSingleton.getBean("ehCacheProvider")).getCacheManager();
                String[] ehcacheNames = ehcacheManager.getCacheNames();
                java.util.Arrays.sort(ehcacheNames);
                for (String ehcacheName : ehcacheNames) {
                    net.sf.ehcache.Cache ehcache = ehcacheManager.getCache(ehcacheName);
                    strOut.append(ehcacheName).append(": ");
                    if (ehcache.isStatisticsEnabled()) {
                        Statistics ehcacheStats = ehcache.getStatistics();
                        String efficiencyStr = "0";
                        if (ehcacheStats.getCacheHits() + ehcacheStats.getCacheMisses() > 0) {
View Full Code Here

* @since 2004-10-21
* @version $Revision: 1.1 $
*/
public class ListAllCaches extends BaseAction {
    public Cache[] getCaches() throws CacheException {
        CacheManager manager = getCacheManager();
        String[] names = manager.getCacheNames();
        Cache[] result = new Cache[names.length];
        for (int i = 0; i < names.length; i++) {
            result[i] = manager.getCache(names[i]);
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of net.sf.ehcache.CacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.