Split out of #228 (fixed for @cache in #259).
Problem
Memcached rejects values larger than its item size limit (1 MB by default, memcached -I) with MemcacheServerError: object too large for cache. #259 makes @cache log this and serve the response unstored. Every other writer still gets the raw pymemcache error:
CacheManager.set / add / get_or_set
StateManager.create_state (large metadata)
SessionManager (large session data)
- direct
backend.set / set_if_absent callers
Redis has a much larger limit (512 MB per value), so the same code can work on Redis and fail on Memcached.
Options
- Keep raising, with a clearer error. Translate the error into a
CacheXError subclass that names the key's size and the server limit. This is the least surprising option for writers whose value must be stored: sessions and states must never be dropped silently.
- Skip the store for pure caches.
CacheManager.set could log and skip like @cache, since a cache miss later is harmless. get_or_set would still return the computed value. add would need a decision, because it reports whether it stored.
- Check the size before sending. Add a
max_item_size option on MemcachedBackend so the check happens without a round trip.
A reasonable split is 1 for sessions, states and the backend API, and 2 for CacheManager. Whatever is chosen, BACKENDS.md should document it per caller. The limit itself is already listed there as of #259.
Split out of #228 (fixed for
@cachein #259).Problem
Memcached rejects values larger than its item size limit (1 MB by default,
memcached -I) withMemcacheServerError: object too large for cache. #259 makes@cachelog this and serve the response unstored. Every other writer still gets the raw pymemcache error:CacheManager.set/add/get_or_setStateManager.create_state(large metadata)SessionManager(large session data)backend.set/set_if_absentcallersRedis has a much larger limit (512 MB per value), so the same code can work on Redis and fail on Memcached.
Options
CacheXErrorsubclass that names the key's size and the server limit. This is the least surprising option for writers whose value must be stored: sessions and states must never be dropped silently.CacheManager.setcould log and skip like@cache, since a cache miss later is harmless.get_or_setwould still return the computed value.addwould need a decision, because it reports whether it stored.max_item_sizeoption onMemcachedBackendso the check happens without a round trip.A reasonable split is 1 for sessions, states and the backend API, and 2 for
CacheManager. Whatever is chosen, BACKENDS.md should document it per caller. The limit itself is already listed there as of #259.