当前位置: 首页>>代码示例>>Java>>正文


Java MemoryUnit类代码示例

本文整理汇总了Java中org.ehcache.config.units.MemoryUnit的典型用法代码示例。如果您正苦于以下问题:Java MemoryUnit类的具体用法?Java MemoryUnit怎么用?Java MemoryUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemoryUnit类属于org.ehcache.config.units包,在下文中一共展示了MemoryUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createCache

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
private void createCache(CacheManager cacheManager, String cacheName, Duration timeToLive, boolean persistentCache) {
	ResourcePoolsBuilder resourcePoolsBuilder = ResourcePoolsBuilder.heap(100);
	if (persistentCache) {
		resourcePoolsBuilder = resourcePoolsBuilder.disk(1, MemoryUnit.MB, true);
	}
	CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Object.class, Object.class,
		resourcePoolsBuilder)
		.withExpiry(Expirations.timeToLiveExpiration(timeToLive))
		.build();

	for (String cache : cacheManager.getCacheNames()) {
		if (cache.equals(cacheName)) {
			log.warn("cache '{}' already exists. skipping creation", cacheName);
			return;
		}
	}

	cacheManager.createCache(cacheName, Eh107Configuration.fromEhcacheCacheConfiguration(cacheConfiguration));
}
 
开发者ID:cronn-de,项目名称:jira-sync,代码行数:20,代码来源:JiraServiceCacheConfig.java

示例2: ServerInterfaceCache

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
private ServerInterfaceCache() {
	this.cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("airports",
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)) 
			)
			.build(true);
	this.airportCache = this.cacheManager.getCache("airports", String.class, String.class);
	this.airplaneCache = this.cacheManager.createCache("airplanes",
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, 
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)).build());
	this.flightCache = this.cacheManager.createCache("flights", 
			CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class, 
					ResourcePoolsBuilder.newResourcePoolsBuilder()
					.heap(10, EntryUnit.ENTRIES)
					.offheap(10, MemoryUnit.MB)).build());
}
 
开发者ID:king-jam,项目名称:cs509,代码行数:21,代码来源:ServerInterfaceCache.java

示例3: cacheManager

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Bean
public CacheManager cacheManager(@Autowired Config config) {
    long ttl = Long.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_TTL));

    double pctOfHeap = Double.valueOf(config.getProperties().getProperty(Config.PROP_CACHE_SIZE));
    long cacheSizeMB = new Double(Runtime.getRuntime().maxMemory() * pctOfHeap / 1048576.0).longValue();

    LogFactory.getLog(getClass()).info(
            String.format("Initializing cache TTL=%d secs, size=%d MB (%.2f percent of max heap)",
                    ttl, cacheSizeMB, pctOfHeap * 100));

    org.ehcache.config.CacheConfiguration<Object, Object> cacheConfiguration = CacheConfigurationBuilder
            .newCacheConfigurationBuilder(Object.class, Object.class,
                    ResourcePoolsBuilder.newResourcePoolsBuilder()
                            .heap(cacheSizeMB, MemoryUnit.MB))
            .withExpiry(Expirations.timeToLiveExpiration(new org.ehcache.expiry.Duration(ttl, TimeUnit.SECONDS)))
            .build();

    Map<String, CacheConfiguration<?, ?>> caches = new HashMap<>();
    caches.put(CACHE_DEFAULT, cacheConfiguration);

    EhcacheCachingProvider provider = (EhcacheCachingProvider) javax.cache.Caching.getCachingProvider();

    // when our cacheManager bean is re-created several times for
    // diff test configurations, this provider seems to hang on to state
    // causing cache settings to not be right. so we always close().
    provider.close();

    DefaultConfiguration configuration = new DefaultConfiguration(
            caches, provider.getDefaultClassLoader());

    return new JCacheCacheManager(
            provider.getCacheManager(provider.getDefaultURI(), configuration));
}
 
开发者ID:codeforkjeff,项目名称:conciliator,代码行数:35,代码来源:Application.java

示例4: createRegistry

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    registry.bind(
        "myConf",
        CacheConfigurationBuilder.newCacheConfigurationBuilder(
            String.class,
            String.class,
            ResourcePoolsBuilder.newResourcePoolsBuilder()
                .heap(100, EntryUnit.ENTRIES)
                .offheap(1, MemoryUnit.MB))
        .build()
    );

    return registry;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:EhcacheConfigurationTest.java

示例5: testProgrammaticConfiguration

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testProgrammaticConfiguration() throws Exception {
    EhcacheManager manager = ehcacheConf.getManager();
    Cache<String, String> cache = manager.getCache("myCacheConf", String.class, String.class);

    ResourcePools pools = cache.getRuntimeConfiguration().getResourcePools();

    SizedResourcePool h = pools.getPoolForResource(ResourceType.Core.HEAP);
    assertNotNull(h);
    assertEquals(100, h.getSize());
    assertEquals(EntryUnit.ENTRIES, h.getUnit());

    SizedResourcePool o = pools.getPoolForResource(ResourceType.Core.OFFHEAP);
    assertNotNull(o);
    assertEquals(1, o.getSize());
    assertEquals(MemoryUnit.MB, o.getUnit());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:EhcacheConfigurationTest.java

示例6: testDiskOffHeapOnHeapCopyPutGet

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testDiskOffHeapOnHeapCopyPutGet() {
  Cache<Long, String> cache = cacheManager.createCache("offHeap", newCacheConfigurationBuilder(Long.class, String.class,
                newResourcePoolsBuilder().heap(2, EntryUnit.ENTRIES).offheap(10, MemoryUnit.MB).disk(100, MemoryUnit.MB))
          .add(new DefaultCopierConfiguration<>(SerializingCopier.<Long>asCopierClass(), DefaultCopierConfiguration.Type.KEY))
          .add(new DefaultCopierConfiguration<>(SerializingCopier.<String>asCopierClass(), DefaultCopierConfiguration.Type.VALUE))
          .build()
  );


  cache.put(42L, "TheAnswer");
  assertCounters(3, 2, 0, 1, 0, 0);
  printSerializationCounters("Put DiskOffHeapOnHeapCopy");
  cache.get(42L);
  assertCounters(1, 1, 1, 0, 2, 0);
  printSerializationCounters("Get DiskOffHeapOnHeapCopy fault");
  cache.get(42L);
  assertCounters(0, 0, 0, 0, 1, 0);
  printSerializationCounters("Get DiskOffHeapOnHeapCopy faulted");

  cache.put(42L, "Wrong ...");
  assertCounters(3, 2, 2, 1, 0, 0);
  printSerializationCounters("Put DiskOffHeapOnHeapCopy (update faulted)");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:25,代码来源:SerializerCountingTest.java

示例7: testOffHeapPutGet

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testOffHeapPutGet() {
  Cache<Long, String> cache = cacheManager.createCache("offHeap", newCacheConfigurationBuilder(Long.class, String.class,
                                        newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).offheap(10, MemoryUnit.MB))
          .build()
  );

  cache.put(42L, "TheAnswer");
  assertCounters(1, 0, 0, 1, 0, 0);
  printSerializationCounters("Put Offheap");
  cache.get(42L);
  assertCounters(0, 0, 1, 0, 1, 0);
  printSerializationCounters("Get Offheap fault");
  cache.get(42L);
  assertCounters(0, 0, 0, 0, 0, 0);
  printSerializationCounters("Get Offheap faulted");

  cache.put(42L, "Wrong ...");
  assertCounters(1, 0, 2, 1, 0, 0);
  printSerializationCounters("Put OffHeap (update faulted)");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:SerializerCountingTest.java

示例8: content

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
private Runnable content(final CountDownLatch latch) {
  return () -> {
    try {
      CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder = CacheManagerBuilder.newCacheManagerBuilder()
        .with(ClusteringServiceConfigurationBuilder.cluster(CLUSTER_URI).autoCreate()
          .defaultServerResource("primary-server-resource")
          .resourcePool("resource-pool-a", 32, MemoryUnit.MB)
          .resourcePool("resource-pool-b", 32, MemoryUnit.MB, "secondary-server-resource"))
        .withCache(CACHE_NAME, CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
          ResourcePoolsBuilder.newResourcePoolsBuilder()
            .with(ClusteredResourcePoolBuilder.clusteredDedicated("primary-server-resource", 32, MemoryUnit.MB)))
          .add(new ClusteredStoreConfiguration(Consistency.STRONG)));

      latch.countDown();
      try {
        latch.await();
      } catch (InterruptedException e) {
        // continue
      }

      clusteredCacheManagerBuilder.build(true);
    } catch (Throwable t) {
      exception.compareAndSet(null, t); // only keep the first exception
    }
  };
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:ClusteredConcurrencyTest.java

示例9: testStatefulSerializerWithDiskStateRepository

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testStatefulSerializerWithDiskStateRepository() throws Exception {
  CacheManagerBuilder<PersistentCacheManager> cmBuilder = newCacheManagerBuilder().with(persistence(temporaryFolder.newFolder()
      .getAbsolutePath()))
      .withCache("myCache", newCacheConfigurationBuilder(Long.class, Person.class, heap(10).disk(50, MemoryUnit.MB, true))
          .withValueSerializer((Class) CompactJavaSerializer.class));
  PersistentCacheManager cacheManager = cmBuilder.build(true);

  Cache<Long, Person> myCache = cacheManager.getCache("myCache", Long.class, Person.class);

  myCache.put(42L, new Person("John", 42));
  myCache.put(35L, new Person("Marie", 35));

  cacheManager.close();

  cacheManager.init();

  myCache = cacheManager.getCache("myCache", Long.class, Person.class);

  assertThat(myCache.get(42L).getName(), is("John"));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:22,代码来源:StatefulSerializerWithStateRepositoryTest.java

示例10: testEventOrderForUpdateThatTriggersEviction

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testEventOrderForUpdateThatTriggersEviction () {
  CacheConfiguration<Long, SerializableObject> cacheConfiguration = newCacheConfigurationBuilder(Long.class, SerializableObject.class,
      newResourcePoolsBuilder()
          .heap(1L, EntryUnit.ENTRIES).offheap(1l, MemoryUnit.MB).build()).build();

  CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("cache", cacheConfiguration)
      .build(true);
  Cache<Long, SerializableObject> cache = cacheManager.getCache("cache", Long.class, SerializableObject.class);
  cache.getRuntimeConfiguration().registerCacheEventListener(listener1, EventOrdering.ORDERED, EventFiring.SYNCHRONOUS, EnumSet
      .of(EventType.EVICTED, EventType.CREATED, EventType.UPDATED, EventType.REMOVED));
  SerializableObject object1 = new SerializableObject(0xAAE60);     // 700 KB
  SerializableObject object2 = new SerializableObject(0xDBBA0);     // 900 KB

  cache.put(1L, object1);
  cache.put(1L, object2);
  assertThat(listener1.eventTypeHashMap.get(EventType.EVICTED), lessThan(listener1.eventTypeHashMap.get(EventType.CREATED)));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:EventNotificationTest.java

示例11: testCacheManagerListener_called_after_configuration_updated

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testCacheManagerListener_called_after_configuration_updated() throws Exception {
  EhcacheManager cacheManager = (EhcacheManager) CacheManagerBuilder.newCacheManagerBuilder()
    .build();

  CacheManagerListener cacheManagerListener =  spy(new AssertiveCacheManagerListener(cacheManager.getRuntimeConfiguration()));
  cacheManager.registerListener(cacheManagerListener);
  cacheManager.init();

  CacheConfiguration<String, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(String.class, String.class,
    newResourcePoolsBuilder()
      .heap(10, EntryUnit.ENTRIES)
      .offheap(1, MemoryUnit.MB))
    .build();

  cacheManager.createCache(CACHE_NAME, cacheConfiguration);
  verify(cacheManagerListener).cacheAdded(eq(CACHE_NAME), (Cache<?, ?>) isNotNull());
  cacheManager.removeCache(CACHE_NAME);
  verify(cacheManagerListener).cacheRemoved(eq(CACHE_NAME), (Cache<?, ?>) isNotNull());
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:21,代码来源:CacheManagerListenerInteractionsTest.java

示例12: testTieredClusteredCache

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testTieredClusteredCache() throws Exception {
  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      newCacheManagerBuilder()
          .with(cluster(CLUSTER_URI).autoCreate())
          .withCache("clustered-cache", newCacheConfigurationBuilder(Long.class, String.class,
                  heap(2)
                  .with(clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))));
  final PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);

  final Cache<Long, String> cache = cacheManager.getCache("clustered-cache", Long.class, String.class);

  cache.put(1L, "value");
  assertThat(cache.get(1L), is("value"));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:18,代码来源:BasicClusteredCacheTest.java

示例13: test3TiersStoreStatsAvailableInContextManager

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void test3TiersStoreStatsAvailableInContextManager() throws Exception {
  PersistentCacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
      .with(new CacheManagerPersistenceConfiguration(new File(getStoragePath(), "StoreStatisticsTest")))
      .withCache("threeTieredCache",
          CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
              newResourcePoolsBuilder()
                  .heap(1, MemoryUnit.MB)
                  .offheap(2, MemoryUnit.MB)
                  .disk(5, MemoryUnit.MB)
              )
      ).build(true);

  Cache<Long, String> cache = cacheManager.getCache("threeTieredCache", Long.class, String.class);

  assertNull(cache.get(0L));

  long onHeapMisses = StoreStatisticsTest.<CachingTierOperationOutcomes.GetOrComputeIfAbsentOutcome>findStat(cache, "getOrComputeIfAbsent", "OnHeap").count(CachingTierOperationOutcomes.GetOrComputeIfAbsentOutcome.MISS);
  assertThat(onHeapMisses, equalTo(1L));
  long offHeapMisses = StoreStatisticsTest.<LowerCachingTierOperationsOutcome.GetAndRemoveOutcome>findStat(cache, "getAndRemove", "OffHeap").count(LowerCachingTierOperationsOutcome.GetAndRemoveOutcome.MISS);
  assertThat(offHeapMisses, equalTo(1L));
  long diskMisses = StoreStatisticsTest.<AuthoritativeTierOperationOutcomes.GetAndFaultOutcome>findStat(cache, "getAndFault", "Disk").count(AuthoritativeTierOperationOutcomes.GetAndFaultOutcome.MISS);
  assertThat(diskMisses, equalTo(1L));

  cacheManager.close();
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:27,代码来源:StoreStatisticsTest.java

示例14: testClusteredCacheWithSerializableValue

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void testClusteredCacheWithSerializableValue() throws Exception {
  final CacheManagerBuilder<PersistentCacheManager> clusteredCacheManagerBuilder =
      newCacheManagerBuilder().with(cluster(CLUSTER_URI).autoCreate())
          .withCache("clustered-cache", newCacheConfigurationBuilder(Long.class, Person.class,
                  newResourcePoolsBuilder().with(clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB))));
  PersistentCacheManager cacheManager = clusteredCacheManagerBuilder.build(true);

  Cache<Long, Person> cache = cacheManager.getCache("clustered-cache", Long.class, Person.class);

  cache.put(38L, new Person("Clustered Joe", 28));

  cacheManager.close();

  cacheManager = clusteredCacheManagerBuilder.build(true);
  cache = cacheManager.getCache("clustered-cache", Long.class, Person.class);

  assertThat(cache.get(38L).name, is("Clustered Joe"));
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:20,代码来源:BasicClusteredCacheTest.java

示例15: test_E_notifs_on_add_cache

import org.ehcache.config.units.MemoryUnit; //导入依赖的package包/类
@Test
public void test_E_notifs_on_add_cache() throws Exception {
  cacheManager.createCache("cache-2", newCacheConfigurationBuilder(
    String.class, String.class,
    newResourcePoolsBuilder()
      .heap(10, EntryUnit.ENTRIES)
      .offheap(1, MemoryUnit.MB)
      .with(clusteredDedicated("primary-server-resource", 2, MemoryUnit.MB)))
    .build());

  ContextContainer contextContainer = readTopology().getClient(ehcacheClientIdentifier).get().getManagementRegistry().get().getContextContainer();
  assertThat(contextContainer.getSubContexts()).hasSize(4);

  TreeSet<String> cNames = contextContainer.getSubContexts().stream().map(ContextContainer::getValue).collect(Collectors.toCollection(TreeSet::new));
  assertThat(cNames).isEqualTo(new TreeSet<>(Arrays.asList("cache-2", "dedicated-cache-1", "shared-cache-2", "shared-cache-3")));

  waitForAllNotifications("SERVER_ENTITY_CREATED", "ENTITY_REGISTRY_AVAILABLE", "EHCACHE_SERVER_STORE_CREATED", "SERVER_ENTITY_FETCHED", "CACHE_ADDED");
}
 
开发者ID:ehcache,项目名称:ehcache3,代码行数:19,代码来源:ClusteringManagementServiceTest.java


注:本文中的org.ehcache.config.units.MemoryUnit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。