本文整理汇总了Java中org.ehcache.config.units.EntryUnit类的典型用法代码示例。如果您正苦于以下问题:Java EntryUnit类的具体用法?Java EntryUnit怎么用?Java EntryUnit使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntryUnit类属于org.ehcache.config.units包,在下文中一共展示了EntryUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: ServerInterfaceCache
import org.ehcache.config.units.EntryUnit; //导入依赖的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());
}
示例2: createRegistry
import org.ehcache.config.units.EntryUnit; //导入依赖的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;
}
示例3: testProgrammaticConfiguration
import org.ehcache.config.units.EntryUnit; //导入依赖的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());
}
示例4: testOffHeapClientClass
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void testOffHeapClientClass() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withClassLoader(getClass().getClassLoader())
.withCache("myCache", newCacheConfigurationBuilder(Long.class, Order.class, newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).offheap(2, MemoryUnit.MB))
.build())
.build(true);
Cache<Long, Order> cache = cacheManager.getCache("myCache", Long.class, Order.class);
Order order = new Order(42L);
cache.put(42L, order);
assertTrue(cache.get(42L) instanceof Order);
cache.replace(42L, order, new Order(-1L));
assertEquals(-1L, cache.get(42L).id);
}
示例5: testEventOrderForUpdateThatTriggersEviction
import org.ehcache.config.units.EntryUnit; //导入依赖的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();
}
示例6: test_eviction
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void test_eviction() throws Exception {
UserManagedCache<Number, String> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(Number.class, String.class)
.withResourcePools(newResourcePoolsBuilder().heap(1, EntryUnit.ENTRIES))
.build(true);
assertThat(cache.getRuntimeConfiguration().getResourcePools().getPoolForResource(ResourceType.Core.HEAP).getSize(),
equalTo(1L));
// we put 3 elements, but there's only capacity for 1
for (int i = 0; i < 3; i++) {
cache.putIfAbsent(i, "" + i);
}
// we must find at most 1 non empty value
int nullValuesFound = 0;
for (int i = 0; i < 3; i++) {
String retrievedValue = cache.get(i);
if (retrievedValue == null) {
nullValuesFound ++;
}
}
assertThat("The capacity of the store is 1, and we found more than 1 non empty value in it !", nullValuesFound, is(2));
}
示例7: eventsTest
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
public void eventsTest() {
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.using(PooledExecutionServiceConfigurationBuilder.newPooledExecutionServiceConfigurationBuilder()
.pool("defaultEventPool", 1, 3).pool("cache2Pool", 2, 2).build())
.withDefaultEventListenersThreadPool(
"defaultEventPool")
.withCache("cache1",
CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES))
.add(CacheEventListenerConfigurationBuilder.newEventListenerConfiguration(
new ListenerObject(), EventType.CREATED, EventType.UPDATED)))
.withCache("cache2", CacheConfigurationBuilder
.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES))
.add(CacheEventListenerConfigurationBuilder.newEventListenerConfiguration(new ListenerObject(),
EventType.CREATED, EventType.UPDATED))
.withEventListenersThreadPool("cache2Pool"))
.build(true);
Cache<Long, String> cache1 = cacheManager.getCache("cache1", Long.class, String.class);
Cache<Long, String> cache2 = cacheManager.getCache("cache2", Long.class, String.class);
cacheManager.close();
}
示例8: setUp
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Before
public void setUp() {
transactionManagerWrapper = new TransactionManagerWrapper(testTransactionManager, new NullXAResourceRegistry());
classLoader = ClassLoader.getSystemClassLoader();
keySerializer = new JavaSerializer<>(classLoader);
valueSerializer = new JavaSerializer<>(classLoader);
CopyProvider copyProvider = new DefaultCopyProvider(new DefaultCopyProviderConfiguration());
keyCopier = copyProvider.createKeyCopier(Long.class, keySerializer);
valueCopier = copyProvider.createValueCopier(valueClass, valueSerializer);
Store.Configuration<Long, SoftLock<String>> onHeapConfig = new StoreConfigurationImpl<>(Long.class, valueClass,
null, classLoader, ExpiryPolicyBuilder.noExpiration(), ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.build(),
0, keySerializer, valueSerializer);
testTimeSource = new TestTimeSource();
eventDispatcher = NullStoreEventDispatcher.nullStoreEventDispatcher();
onHeapStore = new OnHeapStore<>(onHeapConfig, testTimeSource, keyCopier, valueCopier, new NoopSizeOfEngine(), eventDispatcher);
journal = new TransientJournal<>();
}
示例9: threeTiersCacheManager
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void threeTiersCacheManager() throws Exception {
// tag::threeTiersCacheManager[]
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence(new File(getStoragePath(), "myData")))
.withCache("threeTieredCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES)
.offheap(1, MemoryUnit.MB)
.disk(20, MemoryUnit.MB, true)
)
).build(true);
// end::threeTiersCacheManager[]
persistentCacheManager.close();
}
示例10: userManagedDiskCache
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void userManagedDiskCache() throws Exception {
// tag::persistentUserManagedCache[]
LocalPersistenceService persistenceService = new DefaultLocalPersistenceService(new DefaultPersistenceConfiguration(new File(getStoragePath(), "myUserData"))); // <1>
PersistentUserManagedCache<Long, String> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(Long.class, String.class)
.with(new UserManagedPersistenceContext<>("cache-name", persistenceService)) // <2>
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10L, EntryUnit.ENTRIES)
.disk(10L, MemoryUnit.MB, true)) // <3>
.build(true);
// Work with the cache
cache.put(42L, "The Answer!");
assertThat(cache.get(42L), is("The Answer!"));
cache.close(); // <4>
cache.destroy(); // <5>
persistenceService.stop(); // <6>
// end::persistentUserManagedCache[]
}
示例11: userManagedListenerCache
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void userManagedListenerCache() throws Exception {
// tag::userManagedListenerCache[]
UserManagedCache<Long, String> cache = UserManagedCacheBuilder.newUserManagedCacheBuilder(Long.class, String.class)
.withEventExecutors(Executors.newSingleThreadExecutor(), Executors.newFixedThreadPool(5)) // <1>
.withEventListeners(CacheEventListenerConfigurationBuilder
.newEventListenerConfiguration(ListenerObject.class, EventType.CREATED, EventType.UPDATED)
.asynchronous()
.unordered()) // <2>
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(3, EntryUnit.ENTRIES))
.build(true);
cache.put(1L, "Put it");
cache.put(1L, "Update it");
cache.close();
// end::userManagedListenerCache[]
}
示例12: threeTiersCacheManager
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void threeTiersCacheManager() throws Exception {
// tag::threeTiersCacheManager[]
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(CacheManagerBuilder.persistence(new File(getStoragePath(), "myData"))) // <1>
.withCache("threeTieredCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder()
.heap(10, EntryUnit.ENTRIES) // <2>
.offheap(1, MemoryUnit.MB) // <3>
.disk(20, MemoryUnit.MB, true) // <4>
)
).build(true);
Cache<Long, String> threeTieredCache = persistentCacheManager.getCache("threeTieredCache", Long.class, String.class);
threeTieredCache.put(1L, "stillAvailableAfterRestart"); // <5>
persistentCacheManager.close();
// end::threeTiersCacheManager[]
}
示例13: testTieredStore
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void testTieredStore() throws Exception {
CacheConfiguration<Long, String> tieredCacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).disk(10L, MemoryUnit.MB))
.build();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(new CacheManagerPersistenceConfiguration(new File(System.getProperty("java.io.tmpdir") + "/tiered-cache-data")))
.withCache("tiered-cache", tieredCacheConfiguration).build(true);
Cache<Long, String> tieredCache = cacheManager.getCache("tiered-cache", Long.class, String.class);
tieredCache.put(1L, "one");
assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from disk
assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from heap
cacheManager.close();
}
示例14: testTieredOffHeapStore
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void testTieredOffHeapStore() throws Exception {
CacheConfiguration<Long, String> tieredCacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).offheap(10, MemoryUnit.MB))
.build();
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("tieredCache", tieredCacheConfiguration).build(true);
Cache<Long, String> tieredCache = cacheManager.getCache("tieredCache", Long.class, String.class);
tieredCache.put(1L, "one");
assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from offheap
assertThat(tieredCache.get(1L), equalTo("one")); // probably coming from heap
cacheManager.close();
}
示例15: testPersistentDiskCache
import org.ehcache.config.units.EntryUnit; //导入依赖的package包/类
@Test
public void testPersistentDiskCache() throws Exception {
CacheConfiguration<Long, String> cacheConfiguration = CacheConfigurationBuilder.newCacheConfigurationBuilder(Long.class, String.class,
ResourcePoolsBuilder.newResourcePoolsBuilder().heap(10, EntryUnit.ENTRIES).disk(10L, MemoryUnit.MB, true))
.build();
PersistentCacheManager persistentCacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.with(new CacheManagerPersistenceConfiguration(new File(getClass().getClassLoader().getResource(".").toURI().getPath() + "/../../persistent-cache-data")))
.withCache("persistent-cache", cacheConfiguration)
.build(true);
Cache<Long, String> cache = persistentCacheManager.getCache("persistent-cache", Long.class, String.class);
// Comment the following line on subsequent run and see the test pass
cache.put(42L, "That's the answer!");
assertThat(cache.get(42L), is("That's the answer!"));
// Uncomment the following line to nuke the disk store
// persistentCacheManager.destroyCache("persistent-cache");
persistentCacheManager.close();
}