如何将所有项目保存到memcached而不会丢失它们?

时间:2016-10-12 12:26:29

标签: python django memcached

In [11]: from django.core.cache import cache

In [12]: keys = []

In [13]: for i in range(1, 10000):
    ...:     key = "Key%s" % i
    ...:     value = ("Value%s" % i)*5000
    ...:     cache.set(key, value, None)
    ...:     keys.append(key)
    ...:     # check lost keys
    ...:     lost = 0
    ...:     for k in keys:
    ...:         if not cache.get(k):
    ...:             lost += 1
    ...:     if lost:
    ...:         print "Lost %s in %s" % (lost, i)

我正在使用Django,memcached与python-memcached一起使用以下缓存设置:

CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}

对于上面的程序,我开始从i = 1437丢失缓存。你能告诉我该怎么做,我可以将所有项目保存到缓存中吗?

1 个答案:

答案 0 :(得分:0)

您可以通过增加Memcached缓存大小来实现它。