从对象化缓存中驱逐对象 [英] Evict objects from objectify cache

查看:56
本文介绍了从对象化缓存中驱逐对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尤其是 Objectify 团队,

especially Objectify team,

我通过这个代码模式持久化我的对象

I'm persisting my objects through this code pattern

Entity filled = ofy().save().toEntity(myPojo);
filled.setUnindexedProperty( "myStuff", "computedSpecialValue" );
datastore.persist(filled);

回读我的对象,我注意到它们是从缓存中获取的,因为没有通知 Objectify 它应该从缓存中驱逐更新的实体.

Reading back my objects, I noticed they are get from cache since Objectify was not notified that it should evict the updated entity from its cache.

我喜欢 Objectify 缓存功能,因为它节省了我从内存缓存中获取数据并为每次读取重新构建对象的时间,所以我希望我的对象被缓存,但我希望能够驱逐它们.

I like the Objectify cache feature since it saves me the time to grab data from memcache and reconstuct the objects for each read, so I want my objects to be cached, but I want to be able to evict them.

此讨论表示 2013 年年中没有解决方案,https://groups.google.com/forum/#!msg/objectify-appengine/n3FJjnYVVsk/6Xp99zReOKQJ

This discussion says there was no solution in mid 2013, https://groups.google.com/forum/#!msg/objectify-appengine/n3FJjnYVVsk/6Xp99zReOKQJ

如果仍然如此,我希望像

If it's still the case, I'd expect an API like

ofy().save().entity(myPojo).evict();

顺便说一句,如果

Entity filled = ofy().save().toEntity(myPojo);

被替换为

Entity filled = ofy().save().entity(myPojo).toEntity();

当然,这个问题有一个代价高昂的解决方法:

Naturally, there's a costly workaround to the issue:

  • 保存实体两次(手动一次,然后通过对象化)

推荐答案

虽然没有正式的 API 来驱逐缓存条目,但这并不难:

While there is no formal API for evicting cache entries, it's not hard to do:

MemcacheServiceFactory
    .getMemcacheService(ObjectifyFactory.MEMCACHE_NAMESPACE)
    .delete(key.toWebSafeString());

这篇关于从对象化缓存中驱逐对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆