diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-05 21:59:43 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-01-05 21:59:43 -0500 |
commit | 896b6d4cb35ee2048dbd74c256f37f0942ee9e06 (patch) | |
tree | 7a466e6d3575ef5e4daa6d84ba25f13c70c10c2c | |
parent | 02f00ac418fd4e77f0e5da1738dac3ace5c364b9 (diff) | |
download | dogpile-core-896b6d4cb35ee2048dbd74c256f37f0942ee9e06.tar.gz |
- expire time of None means "never expire".
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | dogpile/dogpile.py | 8 | ||||
-rw-r--r-- | tests/test_dogpile.py | 19 |
3 files changed, 25 insertions, 4 deletions
@@ -16,6 +16,8 @@ value can come from the cache, thus eliminating the need for the dogpile lock to hang around persistently. +- expire time of None means "never expire". + 0.2.0 ===== diff --git a/dogpile/dogpile.py b/dogpile/dogpile.py index 6f0d290..84360ef 100644 --- a/dogpile/dogpile.py +++ b/dogpile/dogpile.py @@ -24,7 +24,8 @@ class Dogpile(object): continue to return the previous version of that value. - :param expiretime: Expiration time in seconds. + :param expiretime: Expiration time in seconds. Set to + ``None`` for never expires. :param init: if True, set the 'createdtime' to the current time. :param lock: a mutex object that provides @@ -91,7 +92,10 @@ class Dogpile(object): value is available.""" return not self.has_value or \ - time.time() - self.createdtime > self.expiretime + ( + self.expiretime is not None and + time.time() - self.createdtime > self.expiretime + ) @property def has_value(self): diff --git a/tests/test_dogpile.py b/tests/test_dogpile.py index 98b9de6..bc0031a 100644 --- a/tests/test_dogpile.py +++ b/tests/test_dogpile.py @@ -8,7 +8,7 @@ import math import logging log = logging.getLogger(__name__) -class DogpileTest(TestCase): +class ConcurrencyTest(TestCase): # expiretime, time to create, num usages, time spend using, delay btw usage timings = [ # quick one @@ -327,7 +327,7 @@ class DogpileTest(TestCase): "expected %d" % (len(the_resource), expected_generations) -class SingleCreateTest(TestCase): +class DogpileTest(TestCase): def test_single_create(self): dogpile = Dogpile(2) the_resource = [0] @@ -347,3 +347,18 @@ class SingleCreateTest(TestCase): with dogpile.acquire(create_resource): assert the_resource[0] == 2 + + def test_no_expiration(self): + dogpile = Dogpile(None) + the_resource = [0] + + def create_resource(): + the_resource[0] += 1 + + with dogpile.acquire(create_resource): + assert the_resource[0] == 1 + + with dogpile.acquire(create_resource): + assert the_resource[0] == 1 + +
\ No newline at end of file |