duanchi1230 2015-11-15 21:07
浏览 58
已采纳

在Memcached中正确存储数据

I am using Memchache for storing some data, and single item in memcahce looks like the following structure:

`locale1` => [
   'domain1' => [
        'key1-1' => 'value1-1',
        'key1-2' => 'value1-2'
    ],
   'domain2' => [ ... ]
]

so in memcache I have multiple items with similar keys, values that lays in side locale->domain can be changed by web interface. My question is:

What if I will place all locales to single memcache item called locales_holder, and then will fetch all data from it, would it be critical to performance or its ok?

Thanks!

  • 写回答

1条回答 默认 最新

  • dongzhao1865 2015-11-15 21:40
    关注

    This would not be very efficient. Memcache deletes keys that are not used often or when space is needed.

    Building the keys and storing small to medium sized data gives the best results.

    Memcache key: locale/domain1/key1/1
    Memcache value: 'value1-1'
    

    Whenever something gets changed you don't have to write the entire blob of data back into the memcache instance.

    Also, if you are using multiple servers the data gets distributed better over the servers because it can split up the entire locale section over multiple servers.

    If you have two servers, the memcached client calculates a numeric value from the key and performs a simple calculation on it (for example, modulus) to determine whether it should store the value on the first, or second, configured memcached instance.

    See also: - Memcached best practices - small objects and lots of keys or big objects and few keys? - http://www.ibm.com/developerworks/library/os-memcached/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分