CAS in cache framework

95 views
Skip to first unread message

Alexey Moskvin

unread,
Jan 17, 2014, 1:41:33 PM1/17/14
to django-d...@googlegroups.com
Hi all,
there is a usefull (for me now :)) CAS operation in memcache: http://neopythonic.blogspot.ru/2011/08/compare-and-set-in-memcache.html, but I can't find it in django cache api.
Are there any reasons for it not to be implemented there?
Thank you!

Russell Keith-Magee

unread,
Jan 17, 2014, 8:45:52 PM1/17/14
to Django Developers

I can't see any reason that we *shouldn't* support it - it seems like a reasonable primitive to support. 

The only real issue is ensuring it either is, or can be, implemented on all backends and supported memcache libraries. If you can produce a patch that does this, I'd say it has a good chance of being merged into trunk.

Yours,
Russ Magee %-)


--
You received this message because you are subscribed to the Google Groups "Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/be66496f-80ee-498a-9e38-f3a6d2c0cbdc%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Curtis Maloney

unread,
Jan 17, 2014, 9:58:40 PM1/17/14
to django-d...@googlegroups.com
Is it CAS specifically that you want?  Or a Locking primitive?  Or some other operation?

--
Curtis


ipcam...@gmail.com

unread,
Jun 29, 2021, 1:18:20 PM6/29/21
to Django developers (Contributions to Django itself)
Currently `PylibMC` includes support for CAS: https://sendapatch.se/projects/pylibmc/reference.html#pylibmc.Client.cas

Would a PR be welcome that would implement the `cas` and `gets` methods on the `PylibMCCache` cache backend? This would also require setting the `cas` behavior to `True` in the `CACHES` setting; I could include documentation explaining this in the `PylibMCCache` docs as well.

Thanks so much for maintaining Django. I'd love to help contribute my first PR to Django if this would be welcomed!

Adam Johnson

unread,
Jun 29, 2021, 1:48:41 PM6/29/21
to django-d...@googlegroups.com
pymemcache also supports a cas() method, so that's two backends that could have the other method.

I think the main problem is as Russell highlighted - supporting other backends. It would be nice to see research into emulating cas(), at least on LocMemCache which is often used as a fake during testing. Have you got any input there?

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-develop...@googlegroups.com.

ipcam...@gmail.com

unread,
Jun 29, 2021, 3:12:16 PM6/29/21
to Django developers (Contributions to Django itself)
Thanks Adam! That makes sense to me - I believe Redis transactions are atomic by default so the `cas` method wouldn't apply there. I took a look at the LocMemCache code, and I think that the need for cas in this instance also doesn't exist - because the code uses a threading Lock() to prevent race conditions that cas addresses, see https://github.com/django/django/blob/main/django/core/cache/backends/locmem.py#L38. Perhaps for testing we could simply implement a `cas` method for `LocMemCache` that simply calls `LocMemCache.get`?

I'd be happy to implement the cas() method for both Memcached backends and the dummy method for LocMemCache if that makes sense!

Reply all
Reply to author
Forward
0 new messages