本文整理匯總了Java中javax.cache.CacheManager.createCache方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.createCache方法的具體用法?Java CacheManager.createCache怎麽用?Java CacheManager.createCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.cache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.createCache方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cacheExposesMetrics
import javax.cache.CacheManager; //導入方法依賴的package包/類
@ParameterizedTest
@MethodSource("cachingProviders")
void cacheExposesMetrics(CachingProvider provider) {
CacheManager cacheManager = provider.getCacheManager();
MutableConfiguration<Integer, String> configuration = new MutableConfiguration<>();
configuration.setTypes(Integer.class, String.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
.setStatisticsEnabled(true);
Cache<Integer, String> cache = cacheManager.createCache("a", configuration);
cache.put(1, "test");
MeterRegistry registry = new SimpleMeterRegistry();
JCacheMetrics.monitor(registry, cache, "jcache", emptyList());
assertThat(registry.mustFind("jcache.puts").tags("name", "a").gauge().value()).isEqualTo(1.0);
}
示例2: createCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
/**
* Create a new cache from the given cache manager.
*
* @param cacheName Name of the cache.
* @param keyClass Type of the key class.
* @param valueClass Type of the value class.
* @param defaultExpiryTime Cache expire time in minutes.
* @param cacheConfigMap Cache config map.
* @param cacheManager Cache manager to use to create the cache.
* @param <K> Type of the Key.
* @param <V> Type of the Value.
* @return Created cache.
*/
public static <K, V> Cache<K, V> createCache(String cacheName, Class<K> keyClass, Class<V> valueClass,
int defaultExpiryTime, Map<String, CacheConfig> cacheConfigMap,
CacheManager cacheManager) {
Duration cacheExpiry = new Duration(TimeUnit.MINUTES, getExpireTime(cacheConfigMap, cacheName,
defaultExpiryTime));
boolean isStatisticsEnabled = false;
if (cacheConfigMap.get(cacheName) != null) {
isStatisticsEnabled = cacheConfigMap.get(cacheName).isStatisticsEnabled();
}
MutableConfiguration<K, V> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false)
.setTypes(keyClass, valueClass)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(cacheExpiry))
.setStatisticsEnabled(isStatisticsEnabled);
return cacheManager.createCache(cacheName, configuration);
}
示例3: testCreateCacheWithModifiedExpiryPolicy
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCreateCacheWithModifiedExpiryPolicy()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setExpiryPolicyFactory(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY));
Cache cache = cacheManager.createCache("cache", configuration);
CompleteConfiguration actualConfiguration =
(CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertEquals(ModifiedExpiryPolicy.factoryOf(Duration.ONE_DAY), actualConfiguration.getExpiryPolicyFactory());
}
示例4: testCreateCacheWithTouchedExpiryPolicy
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCreateCacheWithTouchedExpiryPolicy()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE));
Cache cache = cacheManager.createCache("cache", configuration);
CompleteConfiguration actualConfiguration =
(CompleteConfiguration) cache.getConfiguration(CompleteConfiguration.class);
assertEquals(TouchedExpiryPolicy.factoryOf(Duration.ONE_MINUTE), actualConfiguration.getExpiryPolicyFactory());
}
示例5: createCache
import javax.cache.CacheManager; //導入方法依賴的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));
}
示例6: jmxExampleTest
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void jmxExampleTest() throws Exception {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, Integer> config
= new MutableConfiguration<String, Integer>();
config.setTypes(String.class, Integer.class)
.setStatisticsEnabled(true);
cacheManager.createCache("simpleCache", config);
Cache<String, Integer> cache = cacheManager.getCache("simpleCache", String.class, Integer.class);
cache.get("test");
MBeanServer mBeanServer = JMXUtils.getMBeanServer();
System.out.println("mBeanServer:" + mBeanServer);
ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics"
+ ",CacheManager=" + (cache.getCacheManager().getURI().toString())
+ ",Cache=" + cache.getName());
System.out.println("obhectNAme:" + objectName);
// Thread.sleep(Integer.MAX_VALUE);
Long CacheMisses = (Long) mBeanServer.getAttribute(objectName, "CacheMisses");
System.out.println("CacheMisses:" + CacheMisses);
assertEquals(1L, CacheMisses.longValue());
}
示例7: before
import javax.cache.CacheManager; //導入方法依賴的package包/類
@BeforeClass
public static void before() throws Exception {
dataModel = Converters.toDataModel(new XSSFWorkbook(pathDataModel));
CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
MutableConfiguration config = new MutableConfiguration();
config.setStoreByValue(false)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ETERNAL))
.setStatisticsEnabled(false);
cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataSet.class));
cacheManager.createCache(CacheBasedDataSetAccessor.DATA_SET_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataSet.class));
ExternalServices.INSTANCE.setDataSetAccessor(new CacheBasedDataSetAccessor());
expectedValues = new HashMap<>();
SpreadsheetEvaluator evaluator = new SpreadsheetEvaluator(dataModel);
for (int i = expectedRowStart; i <= expectedRowEnd; i++) {
ICellValue value = evaluator.evaluate(A1Address.fromA1Address(expectedColumn + i)).getResult();
expectedValues.put(expectedColumn + i, value.get());
}
}
示例8: main
import javax.cache.CacheManager; //導入方法依賴的package包/類
public static void main(String[] args) {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<String, User> cache = cacheManager.getCache("Users", String.class, User.class);
cache.put("Bob", new User("Bob", "[email protected]"));
User user = cache.get("Bob");
MutableConfiguration<String, User> config =
new MutableConfiguration<String, User>();
config.setTypes(String.class, User.class)
.setStatisticsEnabled(true)
.setStoreByValue(true)
.setExpiryPolicyFactory(AccessedExpiryPolicy.
factoryOf(Duration.ONE_MINUTE));
cacheManager.createCache("Orders", config);
}
示例9: JCacheTemplateCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
public JCacheTemplateCache() {
Iterator<CachingProvider> cachingProviders = Caching.getCachingProviders().iterator();
if (cachingProviders.hasNext()) {
CachingProvider cachingProvider = cachingProviders.next();
CacheManager cacheManager = cachingProvider.getCacheManager();
Configuration<String, Template> config = new MutableConfiguration<String, Template>()
.setTypes(String.class, Template.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 5)));
Cache<String, Template> cache = cacheManager.getCache("TemplateCache", String.class, Template.class);
if (cache == null) {
this.cache = cacheManager.createCache("TemplateCache", config);
} else {
this.cache = cache;
}
} else {
this.cache = null; // to keep compatibility with 0.1.0, but ugly
}
}
示例10: createCacheSameName
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void createCacheSameName() {
CacheManager cacheManager = getCacheManager();
String name1 = "c1";
cacheManager.createCache(name1, new MutableConfiguration());
Cache cache1 = cacheManager.getCache(name1);
assertEquals(cache1, cacheManager.getCache(name1));
ensureOpen(cache1);
try {
cacheManager.createCache(name1, new MutableConfiguration());
} catch (CacheException e) {
//expected
}
Cache cache2 = cacheManager.getCache(name1);
}
示例11: RateLimitingFilter
import javax.cache.CacheManager; //導入方法依賴的package包/類
public RateLimitingFilter(JHipsterProperties jHipsterProperties) {
this.jHipsterProperties = jHipsterProperties;
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
CompleteConfiguration<String, GridBucketState> config =
new MutableConfiguration<String, GridBucketState>()
.setTypes(String.class, GridBucketState.class);
this.cache = cacheManager.createCache(GATEWAY_RATE_LIMITING_CACHE_NAME, config);
this.buckets = Bucket4j.extension(JCache.class).proxyManagerForCache(cache);
}
示例12: customize
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public void customize(CacheManager cacheManager) {
cacheManager.createCache("Customer", new MutableConfiguration<>()
.setExpiryPolicyFactory(TouchedExpiryPolicy.factoryOf(new Duration(MINUTES, 2)))
.setStoreByValue(false)
.setStatisticsEnabled(true));
}
示例13: JCacheStore
import javax.cache.CacheManager; //導入方法依賴的package包/類
public JCacheStore(Factory<ExpiryPolicy> expiryPolicyFactory) {
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<String, Serializable> config = new MutableConfiguration<String, Serializable>()
.setTypes(String.class, Serializable.class);
if (expiryPolicyFactory != null) {
config.setExpiryPolicyFactory(expiryPolicyFactory);
}
cache = cacheManager.getCache("session", String.class, Serializable.class);
if (cache == null)
cache = cacheManager.createCache("session", config);
}
示例14: customize
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public void customize(CacheManager cacheManager) {
cacheManager.createCache("games", new MutableConfiguration<>()
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 3600)))
.setStoreByValue(false)
.setStatisticsEnabled(true));
cacheManager.createCache("users", new MutableConfiguration<>()
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 3600)))
.setStoreByValue(false)
.setStatisticsEnabled(true));
}
示例15: JCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
public JCache(URL url) {
String method = url.getParameter(Constants.METHOD_KEY, "");
String key = url.getAddress() + "." + url.getServiceKey() + "." + method;
// jcache 為SPI實現的全限定類名
String type = url.getParameter("jcache");
CachingProvider provider = type == null || type.length() == 0 ? Caching.getCachingProvider() : Caching.getCachingProvider(type);
CacheManager cacheManager = provider.getCacheManager();
Cache<Object, Object> cache = cacheManager.getCache(key);
if (cache == null) {
try {
//configure the cache
MutableConfiguration config =
new MutableConfiguration<Object, Object>()
.setTypes(Object.class, Object.class)
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000))))
.setStoreByValue(false)
.setManagementEnabled(true)
.setStatisticsEnabled(true);
cache = cacheManager.createCache(key, config);
} catch (CacheException e) {
// 初始化cache 的並發情況
cache = cacheManager.getCache(key);
}
}
this.store = cache;
}