简体   繁体   English

在Memcached中正确存储数据

[英]Proper storing data in Memcached

I am using Memchache for storing some data, and single item in memcahce looks like the following structure: 我正在使用Memchache存储一些数据,memcahce中的单个项目看起来像以下结构:

`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. 因此,在内存缓存中,我有多个具有相似键的项,位于侧面语言环境->域中的值可以通过Web界面进行更改。 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? 如果我将所有语言环境放到一个名为locales_holder的内存缓存项中,然后从中获取所有数据,这对性能或性能是否至关重要?

Thanks! 谢谢!

This would not be very efficient. 这将不是很有效。 Memcache deletes keys that are not used often or when space is needed. Memcache会删除不经常使用或需要空间的密钥。

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. 每当发生任何更改时,您都不必将整个数据块写回到memcache实例中。

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. 如果您有两个服务器,则memcached客户端会从密钥中计算一个数值,然后对其进行简单的计算(例如,模数),以确定是否应将值存储在第一个或第二个配置的memcached实例上。

See also: - Memcached best practices - small objects and lots of keys or big objects and few keys? 另请参阅: -Memcached最佳做法-小对象和大量键,还是大对象和少量键? - http://www.ibm.com/developerworks/library/os-memcached/ -http://www.ibm.com/developerworks/library/os-memcached/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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