我使用新设置来增加 memcached 中的项目大小,但我无法通过 Django 后端存储大于 1mb 的内容。
我知道 memcache
模块需要一些设置来实现它,而 Django 在后端使用这个模块。
最佳答案
来自 Maximum size of object that can be saved in memcached with memcache.py :
There are two entries about that in the memcached FAQ :
What is the maximum data size you can store? Why are items limited to 1 megabyte in size? The answer to the first one is (quoting, emphasis mine) :
The maximum size of a value you can store in memcached is 1 megabyte. If your data is larger, consider clientside compression or splitting the value up into multiple keys.
So I'm guessing your 11MB file is quite too big to fit in one memcached entry.
如果你真的想缓存更大的对象,你将不得不继承 Django 的 MemcachedCache,因为它 doesn't allow you to pass in options :
self._client = self._lib.Client(self._servers, pickleProtocol=pickle.HIGHEST_PROTOCOL)
示例子类实现:
from django.core.cache.backends.memcached import MemcachedCache
class LargeMemcachedCache(MemcachedCache):
"Memcached cache for large objects"
@property
def _cache(self):
if getattr(self, '_client', None) is None:
self._client = self._lib.Client(self._servers,
pickleProtocol=pickle.HIGHEST_PROTOCOL,
server_max_value_length = 1024*1024*10)
return self._client
关于python - 如何告诉 Django,memcached 运行时项目大小大于默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16490819/