Package javax.cache

Examples of javax.cache.CacheManager


  @Test
  public void simpleAPIWithGenericsAndNoTypeEnforcement() {

    //resolve a cache manager
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    //configure the cache
    String cacheName = "sampleCache3";
    MutableConfiguration config = new MutableConfiguration<String, Integer>();
    config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
        .setStatisticsEnabled(true);

    //create the cache
    cacheManager.createCache(cacheName, config);

    //... and then later to get the cache
    Cache<String, Integer> cache = cacheManager.getCache(cacheName);

    //use the cache
    String key = "key";
    Integer value1 = 1;
    cache.put("key", value1);
View Full Code Here


  @Test
  public void simpleAPINoGenericsAndNoTypeEnforcement() {

    //resolve a cache manager
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    //configure the cache
    String cacheName = "sampleCache";
    MutableConfiguration config = new MutableConfiguration();
    config.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
    .setStatisticsEnabled(true);

    //create the cache
    cacheManager.createCache(cacheName, config);

    //... and then later to get the cache
    Cache cache = cacheManager.getCache(cacheName);

    //use the cache
    String key = "key";
    Integer value1 = 1;
    cache.put(key, value1);
View Full Code Here

    @Test
    public void simpleAPITypeEnforcementObject() {

        //resolve a cache manager
        CachingProvider cachingProvider = Caching.getCachingProvider();
        CacheManager cacheManager = cachingProvider.getCacheManager();

        //configure the cache
        MutableConfiguration<Object, Object> config = new MutableConfiguration<>();
        config.setTypes(Object.class, Object.class)
                .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
                .setStatisticsEnabled(true);

        //create the cache
        cacheManager.createCache("simpleCache4", config);

        //... and then later to get the cache
        Cache<Object, Object> cache = Caching.getCache("simpleCache4",
                Object.class, Object.class);
View Full Code Here

  public void accessStatistics() throws MalformedObjectNameException,
      AttributeNotFoundException, MBeanException, ReflectionException,
      InstanceNotFoundException {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<String, Integer> config =
        new MutableConfiguration<String, Integer>();
    config.setTypes(String.class, Integer.class)
        .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
        .setStatisticsEnabled(true);

    Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);

    Set<ObjectName> registeredObjectNames = null;
    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    ObjectName objectName = new ObjectName("javax.cache:type=CacheStatistics"
View Full Code Here

public class TypeSafety {

  @Test
  public void runtimeTypeEnforcement() {
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<String, Integer> config = new
        MutableConfiguration<>();
    config.setTypes(String.class, Integer.class);

    Cache<String, Integer> simpleCache = cacheManager.createCache("simpleCache5", config);

    simpleCache.put("key1", 3);
    Integer value2 = simpleCache.get("key1");

    //Shows how you might try to get around runtime+generics safety
View Full Code Here

   */
  @Test
  public void incrementValue() {

    CachingProvider provider = Caching.getCachingProvider();
    CacheManager manager = provider.getCacheManager();

    MutableConfiguration<String, Integer> configuration =
      new MutableConfiguration<String, Integer>()
        .setTypes(String.class, Integer.class);

    Cache<String, Integer> cache = manager.createCache("example", configuration);

    String key = "counter";
    cache.put(key, 1);

    int previous = cache.invoke(key, new IncrementProcessor<String>());
View Full Code Here


  public void completionListenerExample() {

    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    MutableConfiguration<String, Integer> config = new MutableConfiguration<>();
    config.setTypes(String.class, Integer.class)
        .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
        .setStatisticsEnabled(true);

    Cache<String, Integer> cache = cacheManager.createCache("simpleCache", config);

    HashSet<String> keys = new HashSet<>();
    keys.add("23432lkj");
    keys.add("4fsdldkj");
View Full Code Here

  @Test
  public void simpleAPITypeEnforcement() {

    //resolve a cache manager
    CachingProvider cachingProvider = Caching.getCachingProvider();
    CacheManager cacheManager = cachingProvider.getCacheManager();

    //configure the cache
    MutableConfiguration<String, Integer> config = new MutableConfiguration<>();
    //uses store by reference
    config.setStoreByValue(false)
        .setTypes(String.class, Integer.class)
        .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(ONE_HOUR))
        .setStatisticsEnabled(true);

    //create the cache
    cacheManager.createCache("simpleOptionalCache", config);

    //... and then later to get the cache
    Cache<String, Integer> cache = Caching.getCache("simpleOptionalCache",
        String.class, Integer.class);
View Full Code Here

TOP

Related Classes of javax.cache.CacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.