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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了