本文整理汇总了Java中javax.cache.expiry.AccessedExpiryPolicy类的典型用法代码示例。如果您正苦于以下问题:Java AccessedExpiryPolicy类的具体用法?Java AccessedExpiryPolicy怎么用?Java AccessedExpiryPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AccessedExpiryPolicy类属于javax.cache.expiry包,在下文中一共展示了AccessedExpiryPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configure
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Override
public void configure(Binder binder) {
//programmatically configured cache
Configuration<String, String> programmaticCache =
new MutableConfiguration<String, String>()
.setTypes(String.class, String.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_HOUR))
.setReadThrough(true)
.setWriteThrough(true)
.addCacheEntryListenerConfiguration(new MyCache2EntryListenerConfiguration());
//contribute the cache into BQ
JCacheModule.extend(binder).setConfiguration("myCache2", programmaticCache);
BQCoreModule.extend(binder).addCommand(DemoHazelcastCommand.class);
}
示例2: cacheExposesMetrics
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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);
}
示例3: createCache
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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);
}
示例4: before
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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());
}
}
示例5: JCacheTemplateCache
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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
}
}
示例6: testParametersInURI
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Test
public void testParametersInURI() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider();
Properties p = new Properties();
try (CacheManager cacheManager = cachingProvider.getCacheManager(new URI(cachingProvider.getDefaultURI() + "?secret=testsecret"), cachingProvider.getDefaultClassLoader(), p)) {
MutableConfiguration<String, Integer> config
= new MutableConfiguration<String, Integer>()
.setTypes(String.class, Integer.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
.setStatisticsEnabled(true);
Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);
BlazingCacheManager manager = cacheManager.unwrap(BlazingCacheManager.class);
assertEquals("testsecret", manager.getProperties().get("blazingcache.secret"));
String key = "key";
Integer value1 = 1;
cache.put("key", value1);
Integer value2 = cache.get(key);
assertEquals(value1, value2);
cache.remove(key);
assertNull(cache.get(key));
}
}
示例7: testJSRExample1
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Test
public void testJSRExample1() {
CachingProvider cachingProvider = Caching.getCachingProvider();
Properties p = new Properties();
try (CacheManager cacheManager = cachingProvider.getCacheManager(cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), p)) {
MutableConfiguration<String, Integer> config
= new MutableConfiguration<String, Integer>()
.setTypes(String.class, Integer.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
.setStatisticsEnabled(true);
Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);
String key = "key";
Integer value1 = 1;
cache.put("key", value1);
Integer value2 = cache.get(key);
assertEquals(value1, value2);
cache.remove(key);
assertNull(cache.get(key));
}
}
示例8: main
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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: testCreateConfiguration
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Test
public void testCreateConfiguration() throws Exception {
CompleteConfiguration<String, List> configuration = service.createConfiguration(
String.class, List.class, ImmutableMap.<String, String>builder().
put( Constants.CONFIG_TTL, String.valueOf( 60 * 2 ) ).
put( Constants.CONFIG_TTL_RESET, Constants.ExpiryFunction.ACCESS.name() ).
put( Constants.CONFIG_STORE_BY_VALUE, "false" ).
build()
);
assertThat( configuration.getKeyType(), Matchers.<Class>equalTo( String.class ) );
assertThat( configuration.getValueType(), Matchers.<Class>equalTo( List.class ) );
assertFalse( configuration.isStoreByValue() );
ExpiryPolicy expiryPolicy = configuration.getExpiryPolicyFactory().create();
assertThat( expiryPolicy, instanceOf( AccessedExpiryPolicy.class ) );
assertThat( expiryPolicy.getExpiryForAccess(), equalTo( new Duration( TimeUnit.MINUTES, 2 ) ) );
assertThat( expiryPolicy.getExpiryForUpdate(), nullValue() );
}
示例10: testCacheExpired
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Test
public void testCacheExpired() throws Exception {
Configuration<String, String> configuration =
new MutableConfiguration<String, String>()
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(new Duration(TimeUnit.SECONDS, 3)));
try (CachingProvider provider = Caching.getCachingProvider();
CacheManager manager = provider.getCacheManager();
Cache<String, String> cache = manager.createCache("testCache",
configuration)) {
cache.put("key1", "value1");
cache.put("key2", "value2");
TimeUnit.SECONDS.sleep(1);
cache.get("key2");
TimeUnit.SECONDS.sleep(2);
assertThat(cache.get("key1")).isNull();
assertThat(cache.get("key2")).isEqualTo("value2");
}
}
示例11: testCreateCacheWithUnsupportedAccessedExpiryPolicy
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的package包/类
@Test(expected = UnsupportedOperationException.class)
public void testCreateCacheWithUnsupportedAccessedExpiryPolicy()
{
CacheManager cacheManager = cachingProvider.getCacheManager();
MutableConfiguration<Number, Number> configuration = new MutableConfiguration<>();
configuration.setStoreByValue(false);
configuration.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ZERO));
cacheManager.createCache("cache", configuration);
}
示例12: before
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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(CacheBasedDataModelAccessor.DATA_MODEL_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataModel.class));
cacheManager.createCache(CacheBasedDataModelAccessor.DATA_MODEL_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataModel.class));
cacheManager.createCache(CacheBasedMetaFunctionAccessor.META_FUNCTIONS_CACHE_NAME, config.setTypes(String.class, FunctionMeta.class));
DataModelAccessor dataModelAccessor = new CacheBasedDataModelAccessor();
MetaFunctionAccessor metaFunctionAccessor = new CacheBasedMetaFunctionAccessor();
globalContext = new EvaluationContext();
globalContext.set(DataModelAccessor.class, dataModelAccessor);
globalContext.set(MetaFunctionAccessor.class, metaFunctionAccessor);
dataModelAccessor.add(dataModel); //execution model
Map<DefineFunctionMeta, IDataModel> defineModels = Converters.toMetaFunctions(new XSSFWorkbook(pathDataModel), DefineFunctionMeta.class);
defineModels.forEach((k, v) -> {
metaFunctionAccessor.add(k); //defein meta info with link to DataModel
dataModelAccessor.add(v); //define model
});
}
示例13: before
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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(CacheBasedDataModelAccessor.DATA_MODEL_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataModel.class));
cacheManager.createCache(CacheBasedDataModelAccessor.DATA_MODEL_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataModel.class));
cacheManager.createCache(CacheBasedMetaFunctionAccessor.META_FUNCTIONS_CACHE_NAME, config.setTypes(String.class, FunctionMeta.class));
final ExternalServices external = ExternalServices.INSTANCE;
DataModelAccessor dataModelAccessor = new CacheBasedDataModelAccessor();
MetaFunctionAccessor metaFunctionAccessor = new CacheBasedMetaFunctionAccessor();
external.setDataModelAccessor(dataModelAccessor);
external.setMetaFunctionAccessor(metaFunctionAccessor);
dataModelAccessor.add(dataModel); //execution model
Map<DefineFunctionMeta, IDataModel> defineModels = Converters.toMetaFunctions(new XSSFWorkbook(pathDataModel), DefineFunctionMeta.class);
defineModels.forEach((k, v) -> {
metaFunctionAccessor.add(k); //defein meta info with link to DataModel
dataModelAccessor.add(v); //define model
});
expectedValues = new HashMap<>();
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());
}
}
示例14: before
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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));
cacheManager.createCache(CacheBasedDataModelAccessor.DATA_MODEL_TO_ID_CACHE_NAME, config.setTypes(IDataModelId.class, IDataModel.class));
cacheManager.createCache(CacheBasedDataModelAccessor.DATA_MODEL_TO_NAME_CACHE_NAME, config.setTypes(String.class, IDataModel.class));
cacheManager.createCache(CacheBasedMetaFunctionAccessor.META_FUNCTIONS_CACHE_NAME, config.setTypes(String.class, FunctionMeta.class));
DataModelAccessor dataModelAccessor = new CacheBasedDataModelAccessor();
MetaFunctionAccessor metaFunctionAccessor = new CacheBasedMetaFunctionAccessor();
dataModelAccessor.add(dataModel); //execution model
Map<DefineFunctionMeta, IDataModel> defineModels = new HashMap<>();
defineModels.putAll(Converters.toMetaFunctions(new XSSFWorkbook(pathDataModel), DefineFunctionMeta.class));
defineModels.putAll(Converters.toMetaFunctions(new XSSFWorkbook(pathFuncexecLevel1), DefineFunctionMeta.class));
defineModels.putAll(Converters.toMetaFunctions(new XSSFWorkbook(pathFuncexecLevel2), DefineFunctionMeta.class));
defineModels.forEach((k, v) -> {
metaFunctionAccessor.add(k); //defein meta info with link to DataModel
dataModelAccessor.add(v); //define model
});
ExternalServices.INSTANCE.setDataSetAccessor(new CacheBasedDataSetAccessor());
ExternalServices.INSTANCE.setDataModelAccessor(dataModelAccessor);
ExternalServices.INSTANCE.setMetaFunctionAccessor(metaFunctionAccessor);
}
示例15: before
import javax.cache.expiry.AccessedExpiryPolicy; //导入依赖的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));
cacheManager.createCache(DataSetOptimisationsCache.DATA_SET_TO_LAZY_PARAMETERS, config.setTypes(ILazyDataSet.Parameters.class, IDataSet.class));
cacheManager.createCache(DataSetOptimisationsCache.DATA_SET_DS_LOOKUP_PARAMETERS, config.setTypes(DsLookupParameters.class, List.class));
final ExternalServices external = ExternalServices.INSTANCE;
DataSetAccessor dataSetStorage = new CacheBasedDataSetAccessor();
external.setDataSetAccessor(dataSetStorage);
external.setDataSetOptimisationsCache(new DataSetOptimisationsCache());
final IDataSet dataSet = Converters.toDataSet(new XSSFWorkbook(pathDataSet));
dataSetStorage.add(dataSet);
expectedValues = new HashMap<>();
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());
}
}