1. Ralph Bean
  2. dogpile.core


Mike Bayer  committed f932292

integrate the registry with dogpile

  • Participants
  • Parent commits 8e685bb
  • Branches default

Comments (0)

Files changed (3)

File README.rst

View file
  • Ignore whitespace
     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

View file
  • Ignore whitespace
 from dogpile import Dogpile, SyncReaderDogpile, NeedRegenerationException
-from nameregistry import NameRegistry
 __version__ = '0.2.1'

File dogpile/dogpile.py

View file
  • Ignore whitespace
 import time
 import logging
 from readwrite_lock import ReadWriteMutex
+from nameregistry import NameRegistry
 log = logging.getLogger(__name__)
             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,