Django

Code

Changeset 5703

Show
Ignore:
Timestamp:
07/15/07 01:24:54 (1 year ago)
Author:
gwilson
Message:

Fixed #3012 -- Changed the locmem cache backend to use pickle instead of deepcopy to make it compatible with iterators (which cannot be copied). Patch from Sundance.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r5687 r5703  
    238238    Thomas Steinacher <http://www.eggdrop.ch/> 
    239239    nowell strite 
     240    Sundance 
    240241    Radek Švarz <http://www.svarz.cz/translate/> 
    241242    Swaroop C H <http://www.swaroopch.info> 
  • django/trunk/django/core/cache/backends/locmem.py

    r4265 r5703  
    33from django.core.cache.backends.simple import CacheClass as SimpleCacheClass 
    44from django.utils.synch import RWLock 
    5 import copy, time 
     5import time 
     6try: 
     7    import cPickle as pickle 
     8except ImportError: 
     9    import pickle 
    610 
    711class CacheClass(SimpleCacheClass): 
     
    2125                should_delete = True 
    2226            else: 
    23                 return copy.deepcopy(self._cache[key]) 
     27                try: 
     28                    return pickle.loads(self._cache[key]) 
     29                except pickle.PickleError: 
     30                    return default 
    2431        finally: 
    2532            self._lock.reader_leaves() 
     
    3643        self._lock.writer_enters() 
    3744        try: 
    38             SimpleCacheClass.set(self, key, value, timeout) 
     45            try: 
     46                super(CacheClass, self).set(key, pickle.dumps(value), timeout) 
     47            except pickle.PickleError: 
     48                pass 
    3949        finally: 
    4050            self._lock.writer_leaves() 
  • django/trunk/tests/regressiontests/cache/tests.py

    r5171 r5703  
    55import time, unittest 
    66 
    7 # functions/classes for complex data type tests         
     7# functions/classes for complex data type tests 
    88def f(): 
    99    return 42 
     
    4747        self.assertEqual(cache.has_key("goodbye"), False) 
    4848 
    49     def test_in(self):  
    50         cache.set("hello", "goodbye")  
    51         self.assertEqual("hello" in cache, True)  
    52         self.assertEqual("goodbye" in cache, False)  
     49    def test_in(self): 
     50        cache.set("hello", "goodbye") 
     51        self.assertEqual("hello" in cache, True) 
     52        self.assertEqual("goodbye" in cache, False) 
    5353 
    5454    def test_data_types(self): 
    55         # test data types 
    5655        stuff = { 
    5756            'string'    : 'this is a string', 
     
    6261            'function'  : f, 
    6362            'class'     : C, 
     63            'iter'      : iter([1, 2 ,3]), 
    6464        } 
    6565        for (key, value) in stuff.items(): 
    6666            cache.set(key, value) 
    6767            self.assertEqual(cache.get(key), value) 
    68      
     68 
    6969    def test_expiration(self): 
    7070        # expiration