【问题标题】:Is entity key in memcache the same as in datastoreMemcache 中的实体键是否与数据存储区中的相同
【发布时间】:2015-01-08 19:02:59
【问题描述】:

当我像这样设置内存缓存实体的键时

 syncCache.put(entityKey, entity);

在哪里

 entityKey = entity.getKey();
 entityKeyIdFromDataStore = entityKey.getId();

然后我检索存储在 memcache 中的实体并检索密钥 id

 entity = (Entity) syncCache.get(entityKey);
 entityKeyIdFromCache = entity.getKey().getId();

entityKeyIdFromDataStore 和 entityKeyIdFromCache 会一样吗?

【问题讨论】:

    标签: java google-app-engine google-cloud-datastore


    【解决方案1】:

    是的,它会是一样的。请注意,您可以使用 ID 代替密钥:

    syncCache.put(entityKey.getId(), entity);
    entity = (Entity) syncCache.get(entityKey.getId());
    

    ID 比密钥短得多。当然,这仅适用于没有父级的实体,或者如果您在 Memcache 中仅存储一种实体类型。

    【讨论】:

      猜你喜欢
      • 2012-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多