CacheHandler.java :  » Samples » ew-samples » com » sap » jod » test » protobuf » Android Open Source

Android Open Source » Samples » ew samples 
ew samples » com » sap » jod » test » protobuf » CacheHandler.java
package com.sap.jod.test.protobuf;

import java.util.Collections;

import javax.cache.Cache;
import javax.cache.CacheException;
import javax.cache.CacheManager;

import com.sap.jod.test.protobuf.UserStoreProtos.User;

public class CacheHandler {

  private static CacheHandler instance = null;

  public static CacheHandler getInstance() {
    if (instance==null) {
      instance = new CacheHandler();
      instance.initCache();
    }

    return instance;
  }

  private Cache cache;

  private void initCache() {
    try {
      cache = CacheManager.getInstance().getCacheFactory().createCache(Collections.emptyMap());
    } catch (CacheException e) {
      throw new RuntimeException(e);
    }
  }

  public void clearCache() {
    cache.clear();
  }

  public byte[] get(String key) {
    return (byte[]) cache.get(key);
  }

  public void put(String key, byte[] data) {
    cache.put(key, data);
  }
  
  public String getString(String key) {
    return (String) cache.get(key);
  }

  public void putString(String key, String user) {
    cache.put(key, user);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.