Package com.google.appengine.api.memcache

Examples of com.google.appengine.api.memcache.MemcacheService


    if (msNamespace == null)
      msNamespace = "EntityDAO";
    if (msName == null)
      msName = cls.getSimpleName() + query.toString();
   
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(msNamespace);

    if (ms.get(msName) != null)
    {
      obj = ms.get(msName);
    }
    else
    {
      try
      {
        Class<?> classDef = Class.forName(cls.getName());
        obj = classDef.newInstance();

        Method method = classDef.getMethod("fromEntity", com.google.appengine.api.datastore.Entity.class);
        Entity entity = EntityDAO.getEntity(query);
        method.invoke(obj, entity);

        ms.put(msName, obj);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
View Full Code Here


    if (msNamespace == null)
      msNamespace = "EntityDAO";
    if (msName == null)
      msName = cls.getSimpleName() + name;
   
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(msNamespace);

    if (ms.get(msName) != null)
    {
      obj = ms.get(msName);
    }
    else
    {
      try
      {
        Query query = new Query(cls.getSimpleName());
        query.addFilter("name", FilterOperator.EQUAL, name);

        Class<?> classDef = Class.forName(cls.getName());
        obj = classDef.newInstance();

        Method method = classDef.getMethod("fromEntity", com.google.appengine.api.datastore.Entity.class);
        Entity entity = EntityDAO.getEntity(query);
        method.invoke(obj, entity);

        ms.put(msName, obj);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
View Full Code Here

    if (msNamespace == null)
      msNamespace = "EntityDAO";
    if (msName == null)
      msName = "All" + cls.getSimpleName();
   
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(msNamespace);

    if (ms.get(msName) != null)
    {
      objs = (List)ms.get(msName);
    }
    else
    {
      try
      {
        Query query = new Query(cls.getSimpleName());

        Class<?> classDef = Class.forName(cls.getName());

        Method method = classDef.getMethod("fromEntity", com.google.appengine.api.datastore.Entity.class);
        List<Entity> entities = EntityDAO.getEntities(query);
        objs = new ArrayList();

        for (Entity entity : entities)
        {
          Object obj = classDef.newInstance();
          method.invoke(obj, entity);
          objs.add(cls.cast(obj));
        }

        ms.put(msName, objs);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
View Full Code Here

    if (msNamespace == null)
      msNamespace = "EntityDAO";
    if (msName == null)
      msName = "List" + cls.getSimpleName() + query.toString();
   
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(msNamespace);

    if (ms.get(msName) != null)
    {
      objs = (List)ms.get(msName);
    }
    else
    {
      try
      {
        Class<?> classDef = Class.forName(cls.getName());

        Method method = classDef.getMethod("fromEntity", com.google.appengine.api.datastore.Entity.class);
        List<Entity> entities = EntityDAO.getEntities(query);
        objs = new ArrayList();

        for (Entity entity : entities)
        {
          Object obj = classDef.newInstance();
          method.invoke(obj, entity);
          objs.add(cls.cast(obj));
        }

        ms.put(msName, objs);
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
View Full Code Here

public abstract class TextServlet extends EveDbServlet {

    @Override
    protected void writeResponse(String pathInfo, String acceptHeader, HttpServletResponse resp) throws IOException, JAXBException {
        MemcacheService memcacheService = getMemcacheService();
        String key = new StringBuilder(getClass().getSimpleName()).append("|").append(pathInfo).append("|").append(getDumpVersion()).append("|text").toString();
        String result = (String) memcacheService.get(key);
        if (result == null) {
            logger.info("Key was not found in cache: {}, the result will be cached", key);
            result = provideResponse(pathInfo);
            memcacheService.put(key, result);
        } else {
            logger.info("Key was found in cache: {}", key);
        }
        resp.setContentType("text/plain");
        resp.getWriter().write(result);
View Full Code Here

public class ClearCacheServlet extends HttpServlet {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();
        Stats stats = memcacheService.getStatistics();
        long itemCount = stats.getItemCount();
        logger.info("Clearing memcache, item count in cache: {}", itemCount);
        memcacheService.clearAll();
        resp.getWriter().write("OK, " + itemCount);
    }
View Full Code Here

    private Gson gson;
    private Marshaller marshaller;

    @Override
    protected void writeResponse(String pathInfo, String acceptHeader, HttpServletResponse resp) throws IOException, JAXBException {
        MemcacheService memcacheService = getMemcacheService();
        StringBuilder keyBuilder = new StringBuilder(getClass().getSimpleName()).append("|").append(pathInfo).append("|").append(getDumpVersion());
        if ("application/json".equals(acceptHeader)) {
            String key = keyBuilder.append("|json").toString();
            String result = (String) memcacheService.get(key);
            if (result == null) {
                logger.info("Key was not found in cache: {}, the result will be cached", key);
                StringWriter stringWriter = new StringWriter();
                getGson().toJson(provideResponse(pathInfo), stringWriter);
                result = stringWriter.toString();
                memcacheService.put(key, result);
            } else {
                logger.info("Key was found in cache: {}", key);
            }
            resp.setContentType("application/json");
            resp.getWriter().write(result);
        } else {
            String key = keyBuilder.append("|xml").toString();
            String result = (String) memcacheService.get(key);
            if (result == null) {
                logger.info("Key was not found in cache: {}, the result will be cached", key);
                StringWriter stringWriter = new StringWriter();
                writeXml(provideResponse(pathInfo), stringWriter);
                result = stringWriter.toString();
                memcacheService.put(key, result);
            } else {
                logger.info("Key was found in cache: {}", key);
            }
            resp.setContentType("application/xml");
            resp.getWriter().write(result);
View Full Code Here

   
    Key<Expires> key = ofy().save().entity(exp).now();
    ofy().clear();
    ofy().load().key(key).now()// cached now
   
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService(ObjectifyFactory.MEMCACHE_NAMESPACE);
   
    Object thing = ms.get(key.getString());
    assert thing != null;
   
    Thread.sleep(2000);
   
    Object thing2 = ms.get(key.getString());
    assert thing2 == null;
  }
View Full Code Here

  @Test
  public void testRawCaching() throws Exception {
    // I can not for the life of me figure out why this test passes when the
    // previous test fails.

    MemcacheService cs1 = MemcacheServiceFactory.getMemcacheService("blah");

    com.google.appengine.api.datastore.Key parentKey = KeyFactory.createKey("SimpleParent", "asdf");
    com.google.appengine.api.datastore.Key childKey = KeyFactory.createKey(parentKey, "SimpleEntity", "asdf");

    Entity ent = new Entity(childKey);
    ent.setProperty("foo", "original");
    cs1.put(childKey, ent);

    DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
    ds.put(ent);

    Transaction txn = ds.beginTransaction();
    try {
      Entity ent2 = ds.get(txn, childKey);
 
      //Entity ent2 = (Entity)cs1.get(childKey);
      assert ent2.getProperty("foo").equals("original");
      ent2.setProperty("foo", "changed");
 
      Map<Object, Object> holder = new HashMap<>();
      holder.put(childKey, ent2);
      cs1.putAll(holder);
 
      Map<Object, Object> fetched = cs1.getAll((Collection)Collections.singleton(childKey));
      Entity ent3 = (Entity)fetched.get(childKey);
      assert ent3.getProperty("foo").equals("changed");
    } finally {
      if (txn.isActive())
        txn.rollback();
View Full Code Here

    hr.triv = Ref.create(k1);

    HasRef fetched = ofy().saveClearLoad(hr);

    // Now try to serialize it in memcache.
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();
    ms.put("thing", fetched);

    HasRef serialized = (HasRef)ms.get("thing");
    assert serialized.id.equals(hr.id);
  }
View Full Code Here

TOP

Related Classes of com.google.appengine.api.memcache.MemcacheService

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.