當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheManager.getCache方法代碼示例

本文整理匯總了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;
}
 
開發者ID:ocafebabe,項目名稱:guava-jcache,代碼行數:21,代碼來源:GuavaCacheConcurrentTest.java

示例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;
}
 
開發者ID:wso2,項目名稱:carbon-device-mgt,代碼行數:18,代碼來源:DeviceManagerUtil.java

示例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"));
}
 
開發者ID:bootique,項目名稱:bootique-cayenne,代碼行數:25,代碼來源:CacheInvalidationIT.java

示例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);
}
 
開發者ID:diennea,項目名稱:blazingcache,代碼行數:23,代碼來源:TCKCacheManagerTest.java

示例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);

}
 
開發者ID:kasunbg,項目名稱:jcache-samples,代碼行數:21,代碼來源:JCacheTest.java

示例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;
   }
 
開發者ID:MarcGiffing,項目名稱:bucket4j-spring-boot-starter,代碼行數:17,代碼來源:Bucket4JBaseConfiguration.java

示例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);
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:9,代碼來源:Ex3Service.java

示例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);
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:12,代碼來源:Ex6Service.java

示例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);
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:12,代碼來源:Ex7Service.java

示例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);
  }
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:21,代碼來源:Ex4Service.java

示例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);
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:12,代碼來源:Ex5Service.java

示例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);
}
 
開發者ID:aurbroszniowski,項目名稱:DevoxxFr2017,代碼行數:12,代碼來源:Ex8Service.java

示例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);
}
 
開發者ID:kawasima,項目名稱:enkan,代碼行數:14,代碼來源:JCacheStore.java

示例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;
}
 
開發者ID:wso2,項目名稱:carbon-identity-framework,代碼行數:40,代碼來源:EntitlementEngineCache.java

示例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;
}
 
開發者ID:wso2,項目名稱:carbon-identity-framework,代碼行數:43,代碼來源:EntitlementBaseCache.java


注:本文中的javax.cache.CacheManager.getCache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。