Package com.google.appengine.api.memcache

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


        PrintWriter out = resp.getWriter();

        List<String> headlines =
            new ArrayList<String>(Arrays.asList("...", "...", "..."));

        MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();

        memcache.put("headlines", headlines);

        headlines = (List<String>) memcache.get("headlines");

        memcache.delete("headlines");

        memcache.put("headlines", headlines,
                     Expiration.byDeltaSeconds(300));

        memcache.put("headlines", headlines, null,
                     SetPolicy.ADD_ONLY_IF_NOT_PRESENT);

        boolean headlinesAreCached = memcache.contains("headlines");

        memcache.put("tempnode91512", "...");
        memcache.delete("tempnode91512", 5);
        memcache.put("tempnode91512", "..."); // fails within the 5 second add-lock

        Map<Object, Object> articleSummaries = new HashMap<Object, Object>();
        articleSummaries.put("article00174", "...");
        articleSummaries.put("article05234", "...");
        articleSummaries.put("article15280", "...");
        memcache.putAll(articleSummaries);

        List<Object> articleSummaryKeys = Arrays.<Object>asList(
            "article00174",
            "article05234",
            "article15820");
        articleSummaries = memcache.getAll(articleSummaryKeys);

        memcache.deleteAll(articleSummaryKeys);

        // The new interface for memcache namespaces declares the
        // namespace when constructing the MemcacheService.
        MemcacheService memcacheNews = MemcacheServiceFactory.getMemcacheService("News");
        memcacheNews.put("headlines", headlines);

        MemcacheService memcacheUser = MemcacheServiceFactory.getMemcacheService("User");
        List<String> userHeadlines =
            new ArrayList<String>(Arrays.asList("...", "...", "..."));
        memcacheUser.put("headlines", userHeadlines);

        // Get User:"headlines"
        userHeadlines = (List<String>) memcacheUser.get("headlines");

        // Get News:"headlines"
        headlines = (List<String>) memcacheNews.get("headlines");

        memcache.put("work_done", 0);
View Full Code Here


    return builder.toString();
  }

  @Override
  public GetAccessTokenResult getAccessToken(Iterable<String> scopes) {
    MemcacheService memcache = MemcacheServiceFactory.getMemcacheService(MEMCACHE_NAMESPACE);
    String memcacheKey = memcacheKeyForScopes(scopes);
    GetAccessTokenResult result;
    Object memcacheResult = memcache.get(memcacheKey);
    if (memcacheResult != null) {
      result = (GetAccessTokenResult) memcacheResult;
    } else {
      result = getAccessTokenUncached(scopes);
      Date memcacheExpiration = new Date(result.getExpirationTime().getTime() - 300000);
      memcache.put(memcacheKey, result, Expiration.onDate(memcacheExpiration));
    }
    return result;
  }
View Full Code Here


    private void clearMemcache(ServletContext scx){
        String paramValue = scx.getInitParameter(ScxParamClearMemcache);
        if (null != paramValue && "true".equals(paramValue.trim())){
            MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
            memcache.clearAll();
            Log.info("[cleared]");
        }
        else
            Log.info("[not cleared]");
    }
View Full Code Here

        String logoutUrl = userService.createLogoutURL("/");

        Entity userPrefs = null;
        if (user != null) {
            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();

            String cacheKey = "UserPrefs:" + user.getUserId();
            userPrefs = (Entity) memcache.get(cacheKey);
            if (userPrefs == null) {
                log.warning("CACHE MISS");

                Key userKey = KeyFactory.createKey("UserPrefs", user.getUserId());
                try {
                    userPrefs = ds.get(userKey);
                    memcache.put(cacheKey, userPrefs);
                } catch (EntityNotFoundException e) {
                    // No user preferences stored.
                }
            } else {
                log.warning("CACHE HIT");
View Full Code Here

        DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
        Key userKey = KeyFactory.createKey("UserPrefs", user.getUserId());
        Entity userPrefs = new Entity(userKey);

        MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
        String cacheKey = "UserPrefs:" + user.getUserId();

        try {
            int tzOffset = new Integer(req.getParameter("tz_offset")).intValue();

            userPrefs.setProperty("tz_offset", tzOffset);
            userPrefs.setProperty("user", user);
            ds.put(userPrefs);
            memcache.delete(cacheKey);

        } catch (NumberFormatException nfe) {
            // User entered a value that wasn't an integer. Ignore for now.
        }
View Full Code Here

        UserPrefs userPrefs = null;

        String cacheKey = getCacheKeyForUser(user);

        try {
            MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
            if (memcache.contains(cacheKey)) {
                logger.warning("CACHE HIT: " + cacheKey);
                userPrefs = (UserPrefs) memcache.get(cacheKey);
                return userPrefs;
            }
            logger.warning("CACHE MISS: " + cacheKey);
            // If the UserPrefs object isn't in memcache,
            // fall through to the datastore.
View Full Code Here

        }
    }

    public void cacheSet() {
        try {
            MemcacheService memcache = MemcacheServiceFactory.getMemcacheService();
            memcache.put(getCacheKey(), this);
        } catch (MemcacheServiceException e) {
            // Ignore cache problems, nothing we can do.
        }
    }
View Full Code Here

    {
        if (this.child)
            return this.entered();
        else {
            final long end = (System.currentTimeMillis()+timeout);
            final MemcacheService mc = Store.C.Get();
            do {
                if (this.test(mc))
                    /*
                     */
                    return Lock.Enter(this);
View Full Code Here

            return false;
        }
    }
    public void exit(){
        if (!this.child){
            MemcacheService mc = Store.C.Get();
            if (null != mc)
                this.exit(mc);
        }
    }
View Full Code Here

                throw new AdminAccessException(access);
        }
        query.setKeysOnly();

        final DatastoreService ds = Store.P.Get();
        final MemcacheService mc = Store.C.Get();

        PreparedQuery stmt = ds.prepare(query);

        Iterable<Entity> list = stmt.asIterable();

        for (Entity ent : list){
            final Key key = ent.getKey();
            final Lock lock = new Lock(key);
            if (lock.enter()){
                try {
                    mc.delete(BigTable.ToString(key));

                    ds.delete(key);
                }
                catch (RuntimeException any){
                }
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.