#6124: need a non-pickled locmem cache backend
---------------------------------------+------------------------------------
          Reporter:  [EMAIL PROTECTED]  |         Owner:  nobody               
            Status:  new               |     Milestone:                       
         Component:  Cache system      |       Version:  SVN                  
        Resolution:                    |      Keywords:  cache, locmem, pickle
             Stage:  Accepted          |     Has_patch:  1                    
        Needs_docs:  0                 |   Needs_tests:  0                    
Needs_better_patch:  1                 |  
---------------------------------------+------------------------------------
Comment (by Pascal Varet <[EMAIL PROTECTED]>):

 Hello Luke,

 I can see a few problems with your patch:

 - Well, to start with, it's not a patch. :) You want to give a patch,
 rather than the patched file itself, for two reasons: one, the file may
 have received other changes than your own since, so it's important to
 provide only those lines that you did change, and two, in a patch you can
 provide changes to several files, which, as you'll see below, is relevent
 to this case.

 - Your patch should provide documentation for the option you are adding to
 the locmem cache backend. (That's where you need to provide changes to
 another file.) On that note, you should absolutely document the fact that
 your new option breaks the convention that cached object be picklable (see
 the current cache documentation).

 - Your patch should provide tests. I'm very much not an expert on tests,
 but I think what you should provide is tests that ensure a non-picklable
 object is cached when the option nopickle=true is given, and not cached
 otherwise.

 - Lastly: your patch contains a subtle bug: since you return the same
 object whenever the cache is called, if any caller modifies the object for
 its own purpose, then the object is modified for every caller. This is
 typically bad in the case of cached HTTP responses. See ticket #599, which
 addressed this very same issue back then. This issue is the reason why
 pickling was used in the first place, so presumably your patch should
 provide another, non-pickle-based solution to the same problem.

 All this being said, IMHO, your problem (object persistence) is not the
 one that the Django cache exists to solve. In the Django cache, attempts
 to cache uncacheable objects fail silently, and cached object eventually
 expire -- neither are what you need, right?

 Perhaps the best solution for you would be to implement your own object
 persistence. See, what the locmem cache amounts to is a simple old Python
 dictionary with locks and expiration. Since, unless I'm mistaken, you
 don't need expiration, perhaps a dictionary somewhere is all you need? The
 dictionary will be persisted as long as your Django app keeps running,
 exactly as with the locmem cache backend.

 HTH.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/6124#comment:3>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to