Package javax.cache

Examples of javax.cache.Cache


   * Returns object in cache
   * @param key
   * @return
   */
  public static Object get(Object key){
    Cache cache = getCache();
   
    if (cache != null) return cache.get(key);
   
    return null;
  }
View Full Code Here


   * @param key
   * @param value
   */
  @SuppressWarnings("unchecked")
  public static void put(Object key, Object value){
    Cache cache = getCache();
   
    if (cache != null) cache.put(key, value);
  }
View Full Code Here

   
    if (cache != null) cache.put(key, value);
  }
 
  public static void remove(Object key){
    Cache cache = getCache();
    if (cache != null) cache.remove(key);
  }
View Full Code Here

    if (cache != null) cache.remove(key);
  }
 
  private static Cache getCache(){
    //find in cache first
        Cache cache = null;
        Map<Object,Object> props = new HashMap<Object,Object>();
        props.put(GCacheFactory.EXPIRATION_DELTA, 3600 * 4); //4 hours
        try {
      cache = CacheManager.getInstance().getCacheFactory().createCache(props);
    } catch (CacheException e) {
View Full Code Here

    @SuppressWarnings({ "unchecked", "serial" })
    public void save(CacheableByteArrayOutputStream o) {
      if (data != null) {
        try {
          Cache cache = CacheManager.getInstance().getCacheFactory().createCache(new HashMap() { {
            put(GCacheFactory.EXPIRATION_DELTA, 3600);
          }});
          size = data.size();     
          int storedBytes = 0;
          String sufix = "";
          while(storedBytes < size) {
            byte[] buff = new byte[Math.min(MEMCACHE_LIMIT, size - storedBytes)];
            storedBytes += data.read(buff);
            cache.put(fname + sufix, buff);
            sufix += "X";
          }
          data = null;
        } catch (Exception e) {
          e.printStackTrace();
View Full Code Here

    }

    private byte[] getData() {
      if (data == null) {
        try {
          Cache cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
          int pos = 0;
          byte[] pData = new byte[size];
          byte[] cacheBuf = null;
          String suffix = "";
          while ((cacheBuf = (byte[]) cache.get(fname + suffix)) != null) {
            System.arraycopy(cacheBuf, 0, pData, pos, cacheBuf.length);
            pos += cacheBuf.length;
            suffix += "X";
          }
          return pData;
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  public Page get(String name) {

    Cache cache;

    try {
      cache = CacheManager.getInstance().getCacheFactory()
          .createCache(Collections.emptyMap());
      // Get the value from the cache.
      Page value = (Page) cache.get(name);
      if (value != null) {
        return value;
      }
    } catch (CacheException e) {
      // ...
    }

    DatastoreService datastore = DatastoreServiceFactory
        .getDatastoreService();
    Page page = new Page(name);
    try {
      Entity e = datastore.get(KeyFactory.createKey(
          Page.class.getSimpleName(), name));
      page = new Page(e.getKey().getName(),
          ((Text) e.getProperty(Page.CONTENT)).getValue());
      // Text style = (Text) e.getProperty(Page.STYLE);
      // if (style != null) {
      // page.setStyle(style.getValue());
      // }
      Text diff = (Text) e.getProperty(Page.DIFF);
      if (diff != null) {
        page.setDiff(diff.getValue());
      }

    } catch (EntityNotFoundException e) {
      // e.printStackTrace();
    }
    try {
      cache = CacheManager.getInstance().getCacheFactory()
          .createCache(Collections.emptyMap());
      cache.put(name, page);
    } catch (CacheException e) {
      // ...
    }

    return page;
View Full Code Here

        datastore.put(history);
      }

      try {
        Cache cache = CacheManager.getInstance().getCacheFactory()
            .createCache(Collections.emptyMap());
        cache.put(p.getName(), p);
      } catch (CacheException e) {
        // ...
      }

    } catch (UnsupportedEncodingException e) {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  @Test
  public void testMemCacheHashMap() throws CacheException {
    Cache cache = CacheManager.getInstance().getCacheFactory()
        .createCache(Collections.emptyMap());
    String name = "name";
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("", "");
    cache.put(name, map);
  }
View Full Code Here

      String url_with_hash_fragment = uri
          + rewriteQueryString(queryString);

      // check memcache first

      Cache cache = null;
      String pageSource = null;

      Map<Object, Object> props = new HashMap<Object, Object>();
      props.put(GCacheFactory.EXPIRATION_DELTA, new Integer(3600));

      try {
        cache = CacheManager.getInstance().getCacheFactory()
            .createCache(props);
        // Get the value from the cache.
        pageSource = (String) cache.get(url_with_hash_fragment);
      } catch (CacheException e) {
        // ...
      }

      // ////////////
      if (pageSource == null) {

        // use the headless browser to obtain an HTML snapshot
        URL url = new URL(SCHEME, domain, port, url_with_hash_fragment);
        this.webClient.getOptions().setTimeout(0);
        HtmlPage page = null;

        try {
          page = this.webClient.getPage(url);

          // gae hack because its single threaded
          this.webClient.getJavaScriptEngine().pumpEventLoop(
              PUMP_TIME);

        } catch (IOException ioe) {
          Logger.getLogger("")
              .warning(
                  "Failed to let google index "
                      + url
                      + " Work on increasing server side performance.");
        }
        if (page != null) {
          pageSource = page.asXml();
        }
      }

      ServletOutputStream out = response.getOutputStream();
      out.println(new String(pageSource));
      out.flush();

      // update cache
      if (cache != null) {
        cache.put(url_with_hash_fragment, pageSource);
      }
    } else {
      try {
        /*
         * not an _escaped_fragment_ URL, so move up the chain of
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.