Mike Bayer avatar Mike Bayer committed 3ca9b15

- expire time of None means "never expire".

Comments (0)

Files changed (3)

   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
 =====
 

dogpile/dogpile.py

     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
         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):

tests/test_dogpile.py

 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
             "expected %d" % (len(the_resource), 
                 expected_generations)
 
-class SingleCreateTest(TestCase):
+class DogpileTest(TestCase):
     def test_single_create(self):
         dogpile = Dogpile(2)
         the_resource = [0]
 
         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
+
+        
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.