I was trying to cache a Django model Instance like
class MyModel(models.Model):
...
several atributes, as well as foreign key attributes
...
from pymemcache.client import base
import pickle
obj = MyModel.objects.first()
client = base.Client(("my-cache.pnpnqe.0001.usw2.cache.amazonaws.com", 11211))
client.set("my-key", pickle.dumps(obj), 1000) # 1000 seconds
# and to access I use
obj = pickle.loads(client.get("my-key"))
They both works fine, but sometimes executing the same line:
client.get("my-key")
generates very very strange errors.(different errors like KeyError, OSError) like
Traceback (most recent call last):
File "/opt/python/current/app/proj/utils/Cache.py", line 93, in get_value
return Cache.client.get(key, None)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 481, in get
return self._fetch_cmd(b'get', [key], False).get(key, default)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 823, in _fetch_cmd
prefixed_keys)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 791, in _extract_value
key = remapped_keys[key]
KeyError: b'some-other-cache-key'
and sometimes I get:
Traceback (most recent call last):
File "/opt/python/current/app/proj/utils/Cache.py", line 93, in get_value
return Cache.client.get(key, None)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 481, in get
return self._fetch_cmd(b'get', [key], False).get(key, default)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 833, in _fetch_cmd
raise MemcacheUnknownError(line[:32])
and sometimes, I get
Traceback (most recent call last):
File "/opt/python/current/app/proj/utils/Cache.py", line 93, in get_value
return Cache.client.get(key, None)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 481, in get
return self._fetch_cmd(b'get', [key], False).get(key, default)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 823, in _fetch_cmd
prefixed_keys)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 790, in _extract_value
buf, value = _readvalue(self.sock, buf, int(size))
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 1234, in _readvalue
buf = _recv(sock, RECV_SIZE)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/pymemcache/client/base.py", line 1257, in _recv
return sock.recv(size)
OSError: [Errno 9] Bad file descriptor
I dont want to store the data, is there any fix or any other way of pickling that doesn't create this error.