Ticket #16533: float-cache-timeout.diff

File float-cache-timeout.diff, 1.4 KB (added by Jeff Balogh, 13 years ago)

Force timeouts to be ints in get_memcache_timeout

  • django/core/cache/backends/memcached.py

    diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py
    index e452498..e32fce9 100644
    a b class BaseMemcachedCache(BaseCache):  
    4747            #
    4848            # This means that we have to switch to absolute timestamps.
    4949            timeout += int(time.time())
    50         return timeout
     50        return int(timeout)
    5151
    5252    def add(self, key, value, timeout=0, version=None):
    5353        key = self.make_key(key, version=version)
  • tests/regressiontests/cache/tests.py

    diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py
    index c5349d5..1ab5286 100644
    a b class BaseCacheTests(object):  
    408408        self.assertEqual(self.cache.get('key3'), 'sausage')
    409409        self.assertEqual(self.cache.get('key4'), 'lobster bisque')
    410410
     411    def test_float_timeout(self):
     412        # Make sure a timeout given as a float doesn't crash anything.
     413        self.cache.set("key1", "spam", 100.2)
     414        self.assertEqual(self.cache.get("key1"), "spam")
     415
    411416    def perform_cull_test(self, initial_count, final_count):
    412417        """This is implemented as a utility method, because only some of the backends
    413418        implement culling. The culling algorithm also varies slightly, so the final
Back to Top