Does the following code change not work?
   http://dpaste.com/41855/

Cheers,
Mike

On Mar 28, 1:16 pm, bfrederi <[EMAIL PROTECTED]> wrote:
> Mike,
>
> I'm not exactly sure how to do a read and get the file to be cached in
> memory with the middleware. If you look at the links I posted to my
> code, how would I cache the file within that view I posted? The
> decorator you specified worked perfectly fine for disabling the cache
> middleware for that view, but I actually want the file to be placed in
> cache, and so far I haven't been able to get it to work.
>
> Thanks, Brandon
>
> On Mar 27, 5:45 pm, Mike Axiak <[EMAIL PROTECTED]> wrote:
>
> > Brandon,
>
> > It appears that the Cache Middleware does not read the content from
> > the file before caching the response [1]. I'm not sure if this is a
> > bug or not...though I'd probably lean towards it being a bug. (Do we
> > not cache middleware to *always* evaluate a file object before caching
> > the response?)
> > Anyway, until that behavior gets changed, there's no reason you can't
> > read (via .read()) your files to just send your content.
>
> > If you expect Django to cache all your data, then you have to read the
> > entire file into memory at *some* point. So I see two options:
> >    1. Read all the file contents into memory by calling
> > file_object.read() before putting it into the HttpResponse object.
> >    2. Disabling cache middleware for that view. To do this, you can
> > use the cache_control decorator [2]. E.g.:
> >       @cache_control(max_age=0)
> >       dev view(request): ...
>
> > As it is your kind of giving Django conflicting requests since you're
> > saying "Don't load the file into memory, load it lazily" while also
> > saying "load the entire response into the cache".
>
> > Regards,
> > Mike
>
> > 1:http://code.djangoproject.com/browser/django/trunk/django/middleware/...
> > 2:http://www.djangoproject.com/documentation/cache/#controlling-cache-u...
>
> > On Mar 27, 6:13 pm, bfrederi <[EMAIL PROTECTED]> wrote:
>
> > > I appreciate the help Rajesh,
>
> > > I haven't added any special settings for the cachemiddleware, I just
> > > placed 'django.middleware.cache.CacheMiddleware' in my middleware
> > > classes and that's it. As far as the low-level caching that I have
> > > written into my code using the "from django.core.cache import cache",
> > > all of that is working fine. It's just the middleware that is the
> > > issue. As soon as I set the cache middleware in my middleware classes
> > > setting, that's when I start having problems.
>
> > > Here is an example view, where I try to open a file and it gives me a
> > > "ValueError: I/O operation on closed file":
> > > view (the line it actually executes is line 24):http://dpaste.com/41671/
> > > function it calls (open_system_file):http://dpaste.com/41672/
>
> > > Every part of that view works fine except for when I go to open that
> > > file on line 24. And it works fine in my tests.py, I get the exact
> > > data that I am supposed to from the file (the specific test is on line
> > > 22):http://dpaste.com/41678/(open_system_fileonline 23 is defined
> > > in system_methods on line 3)
>
> > > And as far as stack traces go, I have my mod python error I just gave
> > > you. Here is the apache2 error log (I blocked out my ip out of
> > > paranoia):http://dpaste.com/41682/Idon'tknow what else to give you
> > > that would help as far as problems within the stack. I'm not doing
> > > anything db related, so if there is something else you need me to
> > > post, please mention it by name specifically, in case there is
> > > something I'm not thinking of.
>
> > > Thanks for the help,
> > > Brandon
>
> > > On Mar 27, 4:01 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
> > > > Hi Brandon,
>
> > > > > I would paste in some code examples, but this project is several
> > > > > hundred lines long, and there are several incidences where I open
> > > > > files that is conflicting with the cache middleware.
>
> > > > Not knowing how you have your cache setup (anonymous, all views, low-
> > > > level), it's hard to tell what's causing this problem. You haven't
> > > > included full stack traces either. So, I would suggest including at
> > > > least this:
>
> > > > - A snippet of a view that fails...include at least one file opening
> > > > command.
> > > > - Full stacktraces of the two errors you mentioned along with the
> > > > snippets of your application code that the stack traces point to.
>
> > > > -Rajesh 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to