Commits

Mike Bayer  committed f932292

integrate the registry with dogpile

  • Participants
  • Parent commits 8e685bb

Comments (0)

Files changed (3)

     import pylibmc
     mc_pool = pylibmc.ThreadMappedPool(pylibmc.Client("localhost"))
 
-    from dogpile import Dogpile, NeedRegenerationException, NameRegistry
+    from dogpile import Dogpile, NeedRegenerationException
     import pickle
     import time
 
     def cache(expiration_time)
-        dogpile_registry = NameRegistry(lambda identifier: Dogpile(expiration_time))
+        dogpile_registry = Dogpile.registry(expiration_time))
 
         def get_or_create(key):
 
 
         return get_or_create
 
-Above, we use a ``NameRegistry`` which will give us a ``Dogpile`` object that's 
+Above, we use ``Dogpile.registry()`` to create a name-based "registry" of ``Dogpile``
+objects.  This object will provide to us a ``Dogpile`` object that's 
 unique on a certain name.   When all usages of that name are complete, the ``Dogpile``
 object falls out of scope, so total number of keys used is not a memory issue.
 Then, tell Dogpile that we'll give it the "creation time" that we'll store in our

File dogpile/__init__.py

 from dogpile import Dogpile, SyncReaderDogpile, NeedRegenerationException
-from nameregistry import NameRegistry
 
 __version__ = '0.2.1'
 

File dogpile/dogpile.py

 import time
 import logging
 from readwrite_lock import ReadWriteMutex
+from nameregistry import NameRegistry
 
 log = logging.getLogger(__name__)
 
         else:
             self.createdtime = -1
 
+    @clasmethod
+    def registry(cls, *arg, **kw):
+        """Return a name-based registry of :class:`.Dogpile` objects.
+        
+        The registry is an instance of :class:`.NameRegistry`,
+        and calling its ``get()`` method with an identifying 
+        key (anything hashable) will construct a new :class:`.Dogpile`
+        object, keyed to that key.  Subsequent usages will return
+        the same :class:`.Dogpile` object for as long as the 
+        object remains in scope.
+
+        The given arguments are passed along to the underlying
+        constructor of the :class:`.Dogpile` class.
+
+        """
+        return NameRegistry(lambda identifier: cls(*arg, **kw))
+
     def acquire(self, creator, 
                         value_fn=None, 
                         value_and_created_fn=None):