Package net.sf.ehcache

Examples of net.sf.ehcache.Ehcache


      if (logger.isDebugEnabled()) {
        logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
      }
      Cache rawCache = createCache();
      this.cacheManager.addCache(rawCache);
      Ehcache decoratedCache = decorateCache(rawCache);
      this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
      this.cache = decoratedCache;
    }
  }
View Full Code Here


      EhCacheFactoryBean cacheFb = new EhCacheFactoryBean();
      cacheFb.setCacheManager(cm);
      cacheFb.setCacheName("myCache1");
      cacheFb.setBlocking(true);
      cacheFb.afterPropertiesSet();
      Ehcache myCache1 = cm.getEhcache("myCache1");
      assertTrue(myCache1 instanceof BlockingCache);
    }
    finally {
      cacheManagerFb.destroy();
    }
View Full Code Here

        public Object createEntry(Object key) throws Exception {
          return key;
        }
      });
      cacheFb.afterPropertiesSet();
      Ehcache myCache1 = cm.getEhcache("myCache1");
      assertTrue(myCache1 instanceof SelfPopulatingCache);
      assertEquals("myKey1", myCache1.get("myKey1").getValue());
    }
    finally {
      cacheManagerFb.destroy();
    }
  }
View Full Code Here

        }
        public void updateEntryValue(Object key, Object value) throws Exception {
        }
      });
      cacheFb.afterPropertiesSet();
      Ehcache myCache1 = cm.getEhcache("myCache1");
      assertTrue(myCache1 instanceof UpdatingSelfPopulatingCache);
      assertEquals("myKey1", myCache1.get("myKey1").getValue());
    }
    finally {
      cacheManagerFb.destroy();
    }
  }
View Full Code Here

        }

        if (LOG.isTraceEnabled()) {
            LOG.trace("Cache " + cacheName + " currently contains " + cacheManager.getCache(cacheName).getSize() + " elements");
        }
        Ehcache cache = cacheManager.getCache(cacheName);

        if (!cache.isKeyInCache(key)) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No Key with name: " + key
                        + "presently exists in the cache. It is also possible that the key may have expired in the cache."
                        + " Replacement will not be performed until an appropriate key/value pair is added to (or) found in the cache.");
            }
View Full Code Here

      rawCache = createCache();
      this.cacheManager.addCache(rawCache);
    }

    // Decorate cache if necessary.
    Ehcache decoratedCache = decorateCache(rawCache);
    if (decoratedCache != rawCache) {
      this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
    }
    this.cache = decoratedCache;
  }
View Full Code Here

            cacheManager = CacheManager.create();
        } else {
            cacheManager = CacheManager.create(configFileURL);
        }
       
        Ehcache newCache = new Cache(key, 50000, true, false, DEFAULT_TTL, DEFAULT_TTL);
        cache = cacheManager.addCacheIfAbsent(newCache);
    }
View Full Code Here

    @Test
    public void testPutRetreive()
    {
        CacheManager cacheManager = CacheManager.getInstance();
        Ehcache ehcache = cacheManager.getEhcache( "testCache" );

        ehcache.put( new Element( "testKey", "testValue" ) );
        stats( ehcache );
        Assert.assertEquals( "testValue", ehcache.get( "testKey" ).getObjectValue() );
    }
View Full Code Here

    @Test
    public void testSizing()
    {
        CacheManager cacheManager = CacheManager.getInstance();
        Ehcache ehcache = cacheManager.getEhcache( "testCache" );
        for ( int i = 0; i < 30000; i++ )
        {
            if ( ( i % 1000 ) == 0 )
            {
                System.out.println( "heatbeat " + i );
                stats( ehcache );
            }
            ehcache.put( new Element( i, new byte[1024] ) );
        }
        stats( ehcache );
        Assert.assertTrue( true );
    }
View Full Code Here

    @Test
    public void testOffHeapExceedMemory()
        throws IOException
    {
        CacheManager cacheManager = CacheManager.getInstance();
        Ehcache ehcache = cacheManager.getEhcache( "testCache" );
        Element element = null;
        try
        {
            for ( int i = 0; i < 3000000; i++ )
            {
                if ( ( i % 1000 ) == 0 )
                {
                    System.out.println( "heatbeat 2 " + i );
                    stats( ehcache );
                }
                element = new Element( i, new byte[1024] );
                ehcache.put( element );
            }
            Assert.fail( "CacheException expected for DirectMemory OffHeap Memory Exceeded" );
        }
        catch ( CacheException e )
        {
View Full Code Here

TOP

Related Classes of net.sf.ehcache.Ehcache

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.