简体   繁体   中英

Writing property to memcache, but not to datastore in Objectify?

In Objectify, I can annotate an entity with @Cache to write it to memcache. If I want to ignore certain properties from being written to datastore, I can annotate them with @Ignore.

  • What I am looking for is a way to store a property in memcache, but not in datastore.
  • And I'd like to combine this with .save(onlyCache). {pseudo-code only}

In other words, I would like to be able to have properties, which are only persisted to memcache, but not to the datastore. If the entity is retrieved from memcache, I have these properties populated, otherwise they are empty.

At the same time, I would like to be able to save an entity only to memcache, but not to datastore.

Why does this make sense? Sometimes I have properties, which I only need while a user is online, and where it doesn't matter, should these be missing. For example, imagine I have a User entity which isn't written frequently, but is read often (eg status of friends in a social network) and I want to track presence for each user, where the presence value changes every time the user navigates in my app. It would be nice to be able to store the user to memcache with its current presence indicator already attached, so when it is retrieved, the client receives that entity with its persisted values plus any cached information available. If I could control .save(onlyCache) to tell Objectify if I want to save the entity just to memcache or all the way through to datastore, I could finetune what I want to see and what not.

Does something like that exist in Objectify and/or would it be feasible? Are there any cons that you can see with this approach?

A property not persisted to database should probably not belong to the entity. Runtime properties like the ones you mentioned can be saved to memcache using MemcacheService ( https://cloud.google.com/appengine/docs/java/javadoc/com/google/appengine/api/memcache/MemcacheService ) separately. That would not clutter your code (having too many annotations, @Ingore, @CacheOnly, etc.) and keep the schema clean.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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