Package javax.cache

Examples of javax.cache.Cache


        session.setAttribute("success", "Action success !");
        req.setAttribute("siteConfig", siteConfig);
        req.getRequestDispatcher("/admin/form_system.jsp").forward(req,
            resp);
      } else if (obj != null && obj.equals("cache")) {
        Cache cache = CacheManager.getInstance().getCacheFactory()
            .createCache(Collections.emptyMap());
        cache.clear();
        session.setAttribute("success", "Action success !");
        req.getRequestDispatcher("/admin/form_cache.jsp").forward(req,
            resp);
      } else {
        resp.sendError(4004, "Invalid parameter !");
View Full Code Here


  // GETTING DATA FROM MEMCACHE

  @SuppressWarnings("unchecked")
  public static <K, T extends Serializable> T get(K key) {
    try {
      Cache cache = CacheManager.getInstance().getCacheFactory()
          .createCache(Collections.emptyMap());
      return (T) cache.get(key);
    } catch (InvalidValueException ex) {
      Logger.get().log(Level.WARNING, null, ex);
      return null;
    } catch (CacheException ex) {
      Logger.get().log(Level.SEVERE, null, ex);
View Full Code Here

    Map props = new HashMap();
    props.put(GCacheFactory.EXPIRATION_DELTA_MILLIS, expirationDeltaMillis);

    try {
      Cache cache = CacheManager.getInstance().getCacheFactory()
          .createCache(props);
      cache.put(key, value);
    } catch (CacheException ex) {
      Logger.get().log(Level.SEVERE, null, ex);
    }
  }
View Full Code Here

  @SuppressWarnings({ "unchecked", "rawtypes" })
  public static <K, T extends Serializable> void put(K key, T value) {
    Map props = Collections.emptyMap();

    try {
      Cache cache = CacheManager.getInstance().getCacheFactory()
          .createCache(props);
      cache.put(key, value);
    } catch (CacheException ex) {
      Logger.get().log(Level.SEVERE, null, ex);
    }
  }
View Full Code Here

  // REMOVE A MEMCACHE ENTRY

  public static <K> void remove(K key) {
    try {
      Cache cache = CacheManager.getInstance().getCacheFactory()
          .createCache(Collections.emptyMap());
      cache.remove(key);
    } catch (CacheException ex) {
      Logger.get().log(Level.SEVERE, null, ex);
    }
  }
View Full Code Here

  // FLUSHING MEMCACHE DATA

  public static void flush() {
    try {
      Cache cache = CacheManager.getInstance().getCacheFactory()
          .createCache(Collections.emptyMap());
      cache.clear();
    } catch (CacheException ex) {
      Logger.get().log(Level.SEVERE, null, ex);
    }
  }
View Full Code Here

    // consultar si el resultado est� en la cache
    try {
      Map<Integer, Integer> props = new HashMap<Integer, Integer>();
      props.put(GCacheFactory.EXPIRATION_DELTA, 1800);
      CacheFactory cacheFactory = CacheManager.getInstance().getCacheFactory();
      Cache cache = cacheFactory.createCache(Collections.emptyMap());

      List<FeaturedArticle> articles = (List<FeaturedArticle>) cache.get(FEATURED_ARTICLES_KEY);

      if (articles == null) {
        // si no esta, buscar los 5 art�culos con m�s comentarios
        articles = searchFeaturedArticles();
        // guardar el resultado en la cache
        cache.put(FEATURED_ARTICLES_KEY, articles);
      }
      return articles;
    } catch (CacheException e) {
      System.out.println(e);
      return Collections.EMPTY_LIST;
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    public void addCache(String name) {
      cacheNames.add(name);
      Cache cache = mock(Cache.class);
      given(cache.getName()).willReturn(name);
      given(cacheManager.getCache(name)).willReturn(cache);
    }
View Full Code Here

    @Test
    public void testCachesDestroy() {
        CacheManager cacheManager = cachingProvider1.getCacheManager();
        CacheManager cacheManager2 = cachingProvider2.getCacheManager();
        MutableConfiguration configuration = new MutableConfiguration();
        final Cache c1 = cacheManager.createCache("c1", configuration);
        final Cache c2 = cacheManager2.getCache("c1");
        c1.put("key", "value");
        cacheManager.destroyCache("c1");
        assertTrueEventually(new AssertTask() {
            @Override
            public void run()
                    throws Exception {
                try {
                    c2.get("key");
                    throw new AssertionError("get should throw IllegalStateException");
                } catch (IllegalStateException e) {
                    //ignored as expected
                }
            }
View Full Code Here

    @Test
    public void testCachesDestroyFromOtherManagers() {
        CacheManager cacheManager = cachingProvider1.getCacheManager();
        CacheManager cacheManager2 = cachingProvider2.getCacheManager();
        MutableConfiguration configuration = new MutableConfiguration();
        final Cache c1 = cacheManager.createCache("c1", configuration);
        final Cache c2 = cacheManager2.createCache("c2", configuration);
        c1.put("key", "value");
        c2.put("key", "value");
        cacheManager.close();
        assertTrueAllTheTime(new AssertTask() {
            @Override
            public void run()
                    throws Exception {
                c2.get("key");
            }
        }, 10);
    }
View Full Code Here

TOP

Related Classes of javax.cache.Cache

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.