GAE - 保存数据存储读取
如果我有 2 个“Tables”,
“Table Player”,(字段 - PlayerKey、PlayerName、PlayerUrlPhoto) “Table PlayerGames”,(字段 - PlayerGameKey、PlayerKey、GameDate)
如果我想列出所有游戏,我将在“PlayerGames”中创建一个查询,并显示“玩家”信息,我将必须“GetObjectbyID”来读取 PlayerName和 PlayerUrlPhoto。
最好的方法是什么?
1 - 使用 GetObjectByID 是正确的方法(为每个“PlayerGame”记录多花费 1 个“数据存储读取”) 2 - 将我知道将来需要列出的字段存储在“PlayerGames”中? (作为玩家名和玩家网址照片,保存“数据存储读取”以获取玩家信息) 3 - 其他方式...
- 提醒玩家可以更改他的姓名和照片,因此如果我将姓名和照片存储在“PlayerGames”中,我也必须更新所有记录。 (并且会花费大量的数据存储写入)
有人可以给我一个关于这个的提示吗?
谢谢
if i have 2 "Tables",
"Table Player" , (Fields - PlayerKey, PlayerName, PlayerUrlPhoto)
"Table PlayerGames", (Fields - PlayerGameKey, PlayerKey, GameDate)
if i wanna list all games, i will create a query in "PlayerGames", and to show the "Players" info, i will have to "GetObjectbyID" to read PlayerName and PLayerUrlPhoto.
What is the best way to do this?
1 - Using GetObjectByID is the right way (spending 1 "datastore read" more for each "PlayerGame" record)
2 - Store at "PlayerGames" the fields that i know that i will need to list in the future? (as playername and playerurlphoto, Saving the "DataStore read" to get Player info)
3 - Other way...
- reminding that the player can change his name and his photo, so if i store the name and photo at "PlayerGames" i will have to update all the records too. (and will spend alot of DataStore Writes)
Can someone give me a tip about this?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您只需要在实体前面使用内存缓存即可。当您通过键获取 Player 实体时,首先使用从数据存储键计算出的键检查内存缓存,如果那里有值,则使用它。否则,执行数据存储读取,然后将结果存储在内存缓存中以供将来使用。这将大大减少数据存储读取的次数。
当玩家更新她的记录时,只需在更新数据存储记录后删除memcache值即可。这会强制下一次读取进入数据存储并更新缓存。
It sounds like you just need to use memcache in front of your entities. When you're getting Player entities by key, first check the memcache using a key you calculate from the datastore key, and if there's a value there, use it. Otherwise, perform the datastore read, then store the result in the memcache for future use. This will drastically reduce the number of datastore reads.
When the player updates her record, just delete the memcache value after updating the datastore record. This forces the next read to go to the datastore, and update the cache.
我将“GetObjectByID”替换为“returnmemcache”。
我做了一个像这样的简单功能:
有人有更好的代码吗?
I'm replacing "GetObjectByID" with "returnmemcache".
I did a simple function like this:
Does anyone have better code?