简体   繁体   English

清除内存缓存AppEngine不起作用

[英]Clearing memcache AppEngine not working

I use the memcache session handling in AppEngine. 我在AppEngine中使用内存缓存会话处理。 Sometimes when doing releases I change objects in a way that renders memcache contents obsolete. 有时在发布时,我以使内存缓存内容过时的方式更改对象。 When I do and Im testing I want to be able to clear my session. 当我进行测试时,我希望能够清除会话。

Ive added a servlet to clear memcache that uses: 我已经添加了一个servlet来清除使用以下内容的内存缓存:

        try {
            CacheFactory cacheFactory = CacheManager.getInstance()
                    .getCacheFactory();
            cacheFactory.createCache(Collections.emptyMap()).clear();
            outputMessage(response, "CLEARED cache");
        } catch (CacheException e1) {
            LOG.log(Level.SEVERE, "cache issue", e1);
            outputMessage(response, "cache issue!!!!!!!!");
        }

and I dump out the session contents using: 我使用以下命令转储会话内容:

    Enumeration<String> e = request.getSession().getAttributeNames();

    outputMessage(response, "DUMPING SESSION..");

    while (e.hasMoreElements()) {
        String name = e.nextElement();

        outputMessage(response, "Name:" + name + " value: "
                + request.getSession().getAttribute(name).toString());

    }

Doing a dump of session before and after a clear doesnt look any different. 在清除之前和之后进行会话转储看起来没有什么不同。

Am I using this right? 我使用这个权利吗?

Cheers 干杯

To get around this problem, I usually append a version id to the key of the object stored in memcache. 为了解决这个问题,我通常将版本ID附加到存储在内存缓存中的对象的键中。 For example, instead of: 例如,代替:

memcache.add('key', 'value')

I do: 我做:

version = '1'    
memcache.add(VERSION + '#key', 'value')

Later, if I want to invalidate all the data in memcache, I just change the version number (and the entries already stored in memcache will be automatically deleted when they expire). 以后,如果我想使内存缓存中的所有数据失效,则只需更改版本号(当内存过期时,已存储在内存缓存中的条目将被自动删除)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM