Google Groups

Re: Is file based cache is safe for concurrent process?


Russell Keith-Magee Mar 27, 2013 5:23 PM
Posted in group: Django developers (Contributions to Django itself)

On Thu, Mar 28, 2013 at 7:13 AM, Ivan <ivan...@gmail.com> wrote:

Yes, you are right. But I asked for another reason.
For example, I see, that werkzeug's cache write cache trough temporary file https://github.com/mitsuhiko/werkzeug/blob/master/werkzeug/contrib/cache.py#L660
But Django cache do not use neither, tmp file or file locking.
So, multiple processes can write a file simultaneously. Also, other processes can obtain incomplete data.

I think it's a bug, so I asked a question in this group (django-developers).

Ok - *that* is a different matter. For future reference, if you're suggesting that something might be a bug, it's helpful to make that clear in your question. 

As I said in my response on django-users, the file based cache is primarily there as a proof of concept that the caching API can be targeted at multiple backends. However, if someone were to propose a patch to add file locking or temp file write-throughs, I don't imagine it would be turned down.

So - feel free to open a ticket for this; and if you want to try your hand at a patch, this should be a relatively simple patch to create (although tests could be a little bit complex). As a helper, the django.core.files.locks module already contains some OS-abstracted code for file locking.

Yours,
Russ Magee %-)