Package com.google.appengine.api.memcache

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


    Set<String> prefixedCounters = new HashSet<String>();
    for (String name : counterNames) {
      prefixedCounters.add(slotPrefix + "_" + name); //change each counters name to the slotPrefix_countername
    }

    MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService(namespace);

    return memcacheService.getAll(prefixedCounters);
  }
View Full Code Here


    return memcacheService.deleteAll(counterNames);
  }

  public static void clearMemCache() {
    MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService(NAMESPACE);
    memcacheService.clearAll();
  }
View Full Code Here

    try { //put in a try so that we can have a finally block which resets namespaces
      Key key = KeyFactory.createKey("AuthKey", "master");

      DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();
      MemcacheService memcacheService = MemcacheServiceFactory.getMemcacheService();

      // look for the auth key in the datastore
      Entity authEntity = (Entity) memcacheService.get(KeyFactory.keyToString(key));
      if (authEntity == null) {
        try {
          authEntity = datastoreService.get(key);
          memcacheService.put(KeyFactory.keyToString(key), authEntity);
        } catch (EntityNotFoundException e) {
          _logger.info("Authentication entity not found in memcache or datastore");
          authEntity = null;
        }
      }

      if (null != updateAuth) {
        //if we're updating the auth
        if (null == authEntity || !authEntity.getProperty("secret").equals(updateAuth)) {
          //if there is no auth key, or the auth key doesn't match the one provided
          try {
            URLFetchService fetchService = URLFetchServiceFactory.getURLFetchService();
            String host = URLEncoder.encode(req.getHeader("Host"), "UTF-8");
            HTTPResponse response = fetchService.fetch(new URL(SECURE_HOST + "/auth/?site=" + host + "&auth=" + updateAuth));

            if (response.getResponseCode() == 200) {
              //if successfully received a response, save the new auth key
              String content = new String(response.getContent());
              if (content.equals(new String("OK"))) {
                authEntity = new Entity(key);
                authEntity.setProperty("secret", updateAuth);

                datastoreService.put(authEntity);
                memcacheService.put(KeyFactory.keyToString(key), authEntity);
              }
            }
          } catch (Exception e) {
            _logger.severe("Exception while updating key: " + e);
            return null;
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

    String sayHelloVN = "<?php ob_start(); echo  'gà lợn '.$abc; return ob_get_contents(); ?>";
    try {

      MondayCompiledScript compiledscript = engine.compile(sayHelloVN);

      MemcacheService syncCache = MemcacheServiceFactory
          .getMemcacheService();
      syncCache.put("test", compiledscript);
      long begin = System.nanoTime();

      Bindings b = compiledscript.getEngine().getBindings(
          ScriptContext.ENGINE_SCOPE);
      b.put("abc", "def");
View Full Code Here

  @Autowired
  private ChapterDao chapterDao;

  public Integer getChapterCount() {
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();

    if (!ms.contains(CHAPTER_COUNT_MEMCACHE_KEY)) {
      ms.put(CHAPTER_COUNT_MEMCACHE_KEY, chapterDao.getChapterCount());
    }

    return (Integer) ms.get(CHAPTER_COUNT_MEMCACHE_KEY);
  }
View Full Code Here

    return (Integer) ms.get(CHAPTER_COUNT_MEMCACHE_KEY);
  }

  public Chapter getChapter(Long id) {
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();
    String key = CHAPTER_MEMCACHE_KEY + id;

    if (!ms.contains(key)) {
      ms.put(key, chapterDao.getChapter(id));
    }

    return (Chapter) ms.get(key);
  }
View Full Code Here

    return (Chapter) ms.get(key);
  }

  public List<Chapter> getChapters() {
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();

    if (!ms.contains(CHAPTERS_MEMCACHE_KEY)) {
      ms.put(CHAPTERS_MEMCACHE_KEY, chapterDao.getChapters());
    }

    return (List<Chapter>) ms.get(CHAPTERS_MEMCACHE_KEY);
  }
View Full Code Here

    return (List<Chapter>) ms.get(CHAPTERS_MEMCACHE_KEY);
  }

  public List<Chapter> getActiveChapters() {
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();

    if (!ms.contains(ACTIVE_CHAPTERS_MEMCACHE_KEY)) {
      ms.put(ACTIVE_CHAPTERS_MEMCACHE_KEY, chapterDao.getActiveChapters());
    }

    return (List<Chapter>) ms.get(ACTIVE_CHAPTERS_MEMCACHE_KEY);
  }
View Full Code Here

    return (List<Chapter>) ms.get(ACTIVE_CHAPTERS_MEMCACHE_KEY);
  }

  public List<Chapter> getChapters(Set<Long> ids) {
    MemcacheService ms = MemcacheServiceFactory.getMemcacheService();
    Set<Long> idsToFetch = new HashSet<Long>();

    List<Chapter> chapters = new ArrayList<Chapter>(ids.size());
    for (Long id : ids) {
      if (ms.contains(CHAPTER_MEMCACHE_KEY + id)) {
        chapters.add((Chapter) ms.get(CHAPTER_MEMCACHE_KEY + id));
      } else {
        idsToFetch.add(id);
      }
    }

    if (idsToFetch.size() > 0) {
      List<Chapter> fetchedChapters = chapterDao.getChapters(idsToFetch);
      for (Chapter chapter : fetchedChapters) {
        ms.put(CHAPTER_MEMCACHE_KEY + chapter.getId(), chapter);
        chapters.add(chapter);
      }
    }

    return chapters;
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.