How to tell Django that memcached works with an item size larger than the default?

I am using a new setting to increase the size of an item in memcached, but I cannot store anything larger than 1mb via the Django backend. I know that a module memcacherequires some configuration to achieve this, and Django uses this module in the backend.

+1
source share
1 answer

From the maximum size of an object that can be saved in memcached using memcache.py :

The memcached FAQ has two entries:

  • What is the maximum data size you can save? Why are items limited to 1 megabyte in size? The answer to the first is (quote, emphasis mine):

  • , memcached, 1 . , .

, , 11 , memcached.

, Django MemcachedCache, :

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
+5

All Articles