revsys / django-friendship

Django app to manage following and bi-directional friendships
BSD 3-Clause "New" or "Revised" License
763 stars 183 forks source link

MemcacheServerError: b'object too large for cache' in FriendshipManager #169

Closed acjh closed 2 years ago

acjh commented 2 years ago

Stack trace:

Traceback (most recent call last):
  ...
  File "/path/to/friendship/models.py, line 209, in sent_requests
    cache.set(key, requests)
  File "/path/to/django/core/cache/backends/memcached.py, line 82, in set
    if not self._cache.set(key, value, self.get_backend_timeout(timeout)):
  File "/path/to/pymemcache/client/hash.py, line 358, in set
    return self._run_cmd('set', key, False, *args, **kwargs)
  File "/path/to/pymemcache/client/hash.py, line 334, in _run_cmd
    return self._safely_run_func(
  File "/path/to/pymemcache/client/hash.py, line 214, in _safely_run_func
    result = func(*args, **kwargs)
  File "/path/to/pymemcache/client/base.py, line 462, in set
    return self._store_cmd(b'set', {key: value}, expire, noreply,
  File "/path/to/pymemcache/client/base.py, line 1107, in _store_cmd
    self._raise_errors(line, name)
  File "/path/to/pymemcache/client/base.py, line 940, in _raise_errors
    raise MemcacheServerError(error)
MemcacheServerError: b'object too large for cache'

This is caused by FriendshipManager methods doing select_related queries, which result in large cache items:

https://github.com/revsys/django-friendship/blob/c1cd6b36b40748f12018f53adbeba04bcfb733c7/friendship/models.py#L197-L201