简体   繁体   English

使用 Objectify 的 Appengine 内存缓存过期

[英]Appengine memcache expiration with Objectify

I am using objectify on appengine with the java runtime.我在 java 运行时的 appengine 上使用 objectify。 I am also using memcache via the @Cached annotation for several entities.我还通过 @Cached 注释为多个实体使用内存缓存。 My question is about the behavior of the objectify when putting objects into the datastore.我的问题是关于将对象放入数据存储时对象化的行为。 When putting an entity that has the @Cached annotation, is the memcache updated?当放置一个带有@Cached 注释的实体时,memcache 是否更新? Or any existing cached data for that entity now out of sync with the datastore.或者该实体的任何现有缓存数据现在与数据存储不同步。 I would like to have the memcache updated when I put an object into the datastore, however I don't know if objectify does this by default or if I need to write this myself.当我将 object 放入数据存储区时,我想更新内存缓存,但是我不知道 objectify 是否默认执行此操作,或者我是否需要自己编写。 If the memcache is updated, then I can have a much higher expiration time(or no expiration) for my data.如果内存缓存已更新,那么我的数据可以有更长的过期时间(或没有过期时间)。 FYI I am not using transactions.仅供参考,我没有使用交易。

When you use @Cached, Objectify handles all updates to the memcache for you in a near-transactionally safe manner.当您使用@Cached 时,Objectify 会以近乎事务安全的方式为您处理对内存缓存的所有更新。 It's "near-transactional" because while it won't fall apart under contention, there are rare circumstances under which it could go out of sync - for example, if you hit a DeadlineExceededException or OutOfMemoryException and Google terminates your VM.它是“近事务性的”,因为虽然它不会在竞争中分崩离析,但在极少数情况下它可能 go 不同步 - 例如,如果您遇到 DeadlineExceededException 或 OutOfMemoryException 并且 Google 终止了您的 VM。

Long expiration times are reasonable for most types of cached data.对于大多数类型的缓存数据来说,较长的过期时间是合理的。

Using Objectify, your data in Memcache will never be out of sync with the Datastore (except in some older versions and in exceptional circumstances, such as a really unlucky deadline).使用 Objectify,您在 Memcache 中的数据将永远不会与 Datastore 不同步(某些旧版本和特殊情况除外,例如非常不幸的截止日期)。

I Objectify will just invalidate the Memcache version (so the next "get" will go to the Datastore and write to the Memcache), rather than updating it, though I'm not sure about this bit.我 Objectify 只会使 Memcache 版本无效(因此下一个“获取”将 go 写入数据存储并写入 Memcache),而不是更新它,尽管我不确定这一点。 Either way, Objectify sorts it out for you.无论哪种方式,Objectify 都会为您解决。

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

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