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!

On Tuesday, June 29, 2021 at 1:48:41 PM UTC-4 Adam Johnson wrote:

> 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?
>
> On Tue, 29 Jun 2021 at 18:18, ipcam...@gmail.com <ipcam...@gmail.com> 
> wrote:
>
>> 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!
>> On Friday, January 17, 2014 at 9:58:40 PM UTC-5 Curtis Maloney wrote:
>>
>>> Is it CAS specifically that you want?  Or a Locking primitive?  Or some 
>>> other operation?
>>>
>>> --
>>> Curtis
>>>
>>>
>>> On 18 January 2014 12:45, Russell Keith-Magee <rus...@keith-magee.com> 
>>> wrote:
>>>
>>>>
>>>> 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 %-)
>>>>
>>>>
>>>> On Sat, Jan 18, 2014 at 2:41 AM, Alexey Moskvin <dbf...@gmail.com> 
>>>> wrote:
>>>>
>>>>> 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!
>>>>>
>>>>> -- 
>>>>> 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.
>>>>>
>>>>
>>>> -- 
>>>> 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/CAJxq84_vqVWQfYJ5tGPS1kGZz_O944yFevd1691h6BWbDJp3_w%40mail.gmail.com
>>>> .
>>>
>>>
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>> -- 
>>
> 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.
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/580772ed-75b7-4bc5-9f06-3b153d167bebn%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/580772ed-75b7-4bc5-9f06-3b153d167bebn%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/cd9196c4-524a-4d3f-8633-8b4804a512e2n%40googlegroups.com.
  • Re:... 'Adam Johnson' via Django developers (Contributions to Django itself)
    • ... ipcam...@gmail.com

Reply via email to