本文整理匯總了Java中javax.cache.CacheManager.getCache方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.getCache方法的具體用法?Java CacheManager.getCache怎麽用?Java CacheManager.getCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.cache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.getCache方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: call
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public Collection<ValueObject> call()
throws Exception
{
CachingProvider cachingProvider = Caching.getCachingProvider(GuavaCachingProvider.class.getName());
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<KeyObject, ValueObject> cache =
cacheManager.getCache("workerCache", KeyObject.class, ValueObject.class);
Set<ValueObject> values = new HashSet<>();
for (long id = 0; id < TEST_CACHE_SIZE; id++)
{
values.add(cache.get(new KeyObject(id)));
}
return values;
}
示例2: getDeviceCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
public static Cache<DeviceCacheKey, Device> getDeviceCache() {
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
CacheManager manager = getCacheManager();
Cache<DeviceCacheKey, Device> deviceCache = null;
if (config.getDeviceCacheConfiguration().isEnabled()) {
if(!isDeviceCacheInitialized) {
initializeDeviceCache();
}
if (manager != null) {
deviceCache = manager.<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
} else {
deviceCache = Caching.getCacheManager(DeviceManagementConstants.DM_CACHE_MANAGER).
<DeviceCacheKey, Device>getCache(DeviceManagementConstants.DEVICE_CACHE);
}
}
return deviceCache;
}
示例3: testInvalidate_CustomData
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testInvalidate_CustomData() {
ObjectContext context = SERVER_RUNTIME.newContext();
// make sure Cayenne-specific caches are created...
ObjectSelect<Table1> g1 = ObjectSelect.query(Table1.class).localCache("cayenne1");
assertEquals(0, g1.select(context).size());
// add custom data
CacheManager cacheManager = TEST_RUNTIME.getInstance(CacheManager.class);
Cache<String, String> cache = cacheManager.getCache("cayenne1");
cache.put("a", "b");
assertEquals("b", cache.get("a"));
// generate commit event
context.newObject(Table1.class);
context.commitChanges();
// custom cache entries must expire
assertNull(cache.get("a"));
}
示例4: testReuseCacheManagerGetCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testReuseCacheManagerGetCache() throws Exception {
CachingProvider provider = Caching.getCachingProvider();
URI uri = provider.getDefaultURI();
CacheManager cacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(cacheManager.isClosed());
cacheManager.close();
assertTrue(cacheManager.isClosed());
try {
cacheManager.getCache("nonExistent", null, null);
fail();
} catch (IllegalStateException e) {
//expected
}
CacheManager otherCacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(otherCacheManager.isClosed());
assertNotSame(cacheManager, otherCacheManager);
}
示例5: 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);
}
示例6: jCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
/**
* This methods
*
* @param cacheName the name of the cache to retrieve
* @param cacheManager
* @return
*/
@SuppressWarnings("unchecked")
public Cache<String, GridBucketState> jCache(String cacheName, CacheManager cacheManager) {
Cache springCache = cacheManager.getCache(cacheName);
if(springCache == null) {
throw new JCacheNotFoundException(cacheName);
}
return (Cache<String, GridBucketState>) springCache;
}
示例7: Ex3Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex3Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex3.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache3", Long.class, Person.class);
}
示例8: Ex6Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex6Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex6.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache6", Long.class, Person.class);
// there unfortunately isn't a public API to read statistics at the moment, see:
// https://github.com/ehcache/ehcache3/issues/1940
managementRegistry = getManagementRegistryService(cacheManager);
}
示例9: Ex7Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex7Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex7.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache7", Long.class, Person.class);
// there unfortunately isn't a public API to read statistics at the moment, see:
// https://github.com/ehcache/ehcache3/issues/1940
managementRegistry = getManagementRegistryService(cacheManager);
}
示例10: Ex4Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex4Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex4.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache4", Long.class, Person.class);
try {
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics,CacheManager="
+ getClass().getResource("/ehcache-ex4.xml")
.toURI()
.toString()
.replace(":", ".") + ",Cache=someCache4");
cacheStatisticsMXBean = MBeanServerInvocationHandler.newProxyInstance(beanServer, objectName, CacheStatisticsMXBean.class, false);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例11: Ex5Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex5Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex5.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache5", Long.class, Person.class);
// there unfortunately isn't a public API to read statistics at the moment, see:
// https://github.com/ehcache/ehcache3/issues/1940
managementRegistry = getManagementRegistryService(cacheManager);
}
示例12: Ex8Service
import javax.cache.CacheManager; //導入方法依賴的package包/類
public Ex8Service() throws URISyntaxException {
CachingProvider cachingProvider = Caching.getCachingProvider("org.ehcache.jsr107.EhcacheCachingProvider");
CacheManager cacheManager = cachingProvider.getCacheManager(
getClass().getResource("/ehcache-ex8.xml").toURI(),
getClass().getClassLoader());
cache = cacheManager.getCache("someCache8", Long.class, Person.class);
// there unfortunately isn't a public API to read statistics at the moment, see:
// https://github.com/ehcache/ehcache3/issues/1940
managementRegistry = getManagementRegistryService(cacheManager);
}
示例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: getEntitlementCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
private Cache<Integer, EntitlementEngine> getEntitlementCache() {
Cache<Integer, EntitlementEngine> cache;
CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager(ENTITLEMENT_ENGINE_CACHE_MANAGER);
if (cacheManager != null) {
if (cacheBuilder == null) {
Properties properties = EntitlementServiceComponent.getEntitlementConfig().getEngineProperties();
String engineCachingInterval = properties.getProperty(PDPConstants.ENTITLEMENT_ENGINE_CACHING_INTERVAL);
long entitlementEngineCachingInterval = DEFAULT_ENTITLEMENT_ENGINE_CACHING_INTERVAL;
if (engineCachingInterval != null) {
try {
entitlementEngineCachingInterval = Long.parseLong(engineCachingInterval);
} catch (NumberFormatException e) {
log.warn("Invalid value for " + PDPConstants.ENTITLEMENT_ENGINE_CACHING_INTERVAL + ". Using " +
"default value " + entitlementEngineCachingInterval + " seconds.");
}
} else {
if (log.isDebugEnabled()) {
log.debug(PDPConstants.ENTITLEMENT_ENGINE_CACHING_INTERVAL + " not set. Using default value " +
entitlementEngineCachingInterval + " seconds.");
}
}
cacheManager.removeCache(ENTITLEMENT_ENGINE_CACHE);
cacheBuilder = cacheManager.<Integer, EntitlementEngine>createCacheBuilder(ENTITLEMENT_ENGINE_CACHE).
setExpiry(CacheConfiguration.ExpiryType.ACCESSED,
new CacheConfiguration.Duration(TimeUnit.SECONDS, entitlementEngineCachingInterval)).
setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
new CacheConfiguration.Duration(TimeUnit.SECONDS, entitlementEngineCachingInterval));
cache = cacheBuilder.build();
} else {
cache = cacheManager.getCache(ENTITLEMENT_ENGINE_CACHE);
}
} else {
cache = Caching.getCacheManager().getCache(ENTITLEMENT_ENGINE_CACHE);
}
if (log.isDebugEnabled()) {
log.debug("created authorization cache : " + cache);
}
return cache;
}
示例15: getEntitlementCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
/**
* Getting existing cache if the cache available, else returns a newly created cache.
* This logic handles by javax.cache implementation
*
* @return
*/
private Cache<K, V> getEntitlementCache() {
Cache<K, V> cache = null;
CacheManager cacheManager = Caching.getCacheManagerFactory().getCacheManager(ENTITLEMENT_CACHE_MANAGER);
if (this.cacheTimeout > 0) {
if (cacheBuilder == null) {
synchronized (Entitlement_CACHE_NAME.intern()) {
if (cacheBuilder == null) {
cacheManager.removeCache(Entitlement_CACHE_NAME);
this.cacheBuilder = cacheManager.<K, V>createCacheBuilder(Entitlement_CACHE_NAME).
setExpiry(CacheConfiguration.ExpiryType.MODIFIED,
new CacheConfiguration.Duration(TimeUnit.SECONDS, cacheTimeout)).
setStoreByValue(false);
cache = cacheBuilder.build();
if (cacheEntryUpdatedListener != null) {
this.cacheBuilder.registerCacheEntryListener(cacheEntryUpdatedListener);
}
if (cacheEntryCreatedListener != null) {
this.cacheBuilder.registerCacheEntryListener(cacheEntryCreatedListener);
}
if (log.isDebugEnabled()) {
String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
log.debug("Cache : " + Entitlement_CACHE_NAME + " is built with time out value " + ": " +
cacheTimeout + " for tenant domain : " + tenantDomain);
}
}
}
} else {
cache = cacheManager.getCache(Entitlement_CACHE_NAME);
}
} else {
cache = cacheManager.getCache(Entitlement_CACHE_NAME);
}
return cache;
}