Thursday, October 27, 2011

Re: CAS and Django cache

Yes, get followed by set can lead to data loss. 

What you want is cache.add(). This sets the value if and only if there is no existing value. Its atomic on backends that support it - notably memcached.  

Sent from my iPhone, please excuse any typos

On 27 Oct 2011, at 07:26, Dan Julius <dan@icvt-tech.com> wrote:

Couldn't that potentially overwrite a value set by a different thread?

Dan

On Thu, Oct 27, 2011 at 7:13 AM, Kurtis Mullins <kurtis.mullins@gmail.com> wrote:
umm, I'm not sure if "check-and-set" is some cache-specific lingo or not. But if you want to see if a value isn't set, check to see if it's None type... example:

if cache.get('key') is None:
    cache.set('key', 'value', cache_seconds)

Sorry if that's not at all what you're talking about :)


On Wed, Oct 26, 2011 at 6:29 PM, dmitry b <dmitry.maven@gmail.com> wrote:
Can I do check-and-set operations using Django's cache api?


Thanks
D.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment