What is the contract of a cache backend regarding errors?

65 views
Skip to first unread message

Jean Hominal

unread,
Dec 25, 2016, 9:02:46 AM12/25/16
to Django developers (Contributions to Django itself)
Hello,

I am considering writing a cache backend for Django based on a recent Couchbase SDK (2.0+).

While it is quite straightforward to write, I would like to know what is expected from a cache backend when errors happen.

With my experience using the python-memcached backend, my understanding is that:

 * On read operations, any errors result in a "None" return value (as if the value was not found);
 * On write operations, errors are silenced, with one exception;
 * On an "add" operation, if e.g. a network error has happened, "0" is returned instead of "False". That lets a client make a distinction between such errors and the key already existing.

Is that understanding accurate? In particular, is the third point contractual?

Thank you in advance.

Adam Johnson

unread,
Dec 26, 2016, 11:59:35 AM12/26/16
to django-d...@googlegroups.com
Hi Jean,

I wrote a cache backend for MySQL in Django-MySQL and didn't add any special error handling. Like the builtin database cache backend, it uses the same connection as the ORM, so if an error does occur it's pretty likely the whole request is broken anyway.

If you look at the code, Django's memcache backend makes no contract about errors, delegating that to the underlying library: https://github.com/django/django/blob/master/django/core/cache/backends/memcached.py . So I think all three points of your understanding are more to do with how python-memcached works rather than a contract Django enforces. If you check the other cache backends where all the logic is in Django, such as filebased, they don't silence any unexpected errors.

Adam




--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/12bdf965-eba7-4f81-8ce0-bd8803d4d726%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Adam
Reply all
Reply to author
Forward
0 new messages