如何通过memcached存储大于1MB的值?

2024-04-20 07:57:47 发布

您现在位置:Python中文网/ 问答频道 /正文

一开始,我使用参数-I 2m安装了memcached 1.4.1,但它没有工作。然后我安装了memcached 1.4.25,而{}也不工作。在django中,cache.set(key,value)当值大小超过1 MB时,它返回None,并且缓存中不存储任何值。在

根据一些文章,我可以将大值存储到多个键中,每个值小于1MB,就可以了。但是密钥管理是有问题的。在

然后我修改了源代码memcached.c

settings.item_size_max = 1024 * 1024; /* The famous 1MB 

反映:

^{pr2}$

在重新编译之后,它又失败了。它仍然不存储大于1M的值

如何通过memcached成功存储大于等于1MB的密钥?在

版本:

CentOS 7, python 2.7.5, django 1.7

The default maximum object size is 1MB. In memcached 1.4.2 and later, you can change the maximum size of an object using the -I command line option. For versions before this, to increase this size, you have to re-compile memcached. You can modify the value of the POWER_BLOCK within the slabs.c file within the source. In memcached 1.4.2 and higher, you can configure the maximum supported object size by using the -I command-line option. For example, to increase the maximum object size to 5MB:

$ memcached -I 5m

If an object is larger than the maximum object size, you must manually split it. memcachedis very simple: you give it a key and some data, it tries to cache it in RAM. If you try to store more than the default maximum size, the value is just truncated for speed reasons.


Tags: andthetodjangokeyyoucachesize