Mike Bayer avatar Mike Bayer committed ce34993

- [bug] Using dogpile.core 0.4.0 now, fixes a critical
bug whereby dogpile pileup could occur on first value
get across multiple processes, due to reliance upon
a non-shared creation time. This is dogpile.core
issue #1.

Comments (0)

Files changed (3)

+0.4.0
+=====
+- [bug] Using dogpile.core 0.4.0 now, fixes a critical
+  bug whereby dogpile pileup could occur on first value
+  get across multiple processes, due to reliance upon
+  a non-shared creation time.  This is dogpile.core
+  issue #1.
+
+- [bug] Fixed missing __future__ with_statement
+  directive in region.py.
+
 0.3.1
 =====
 - [bug] Fixed the mako_cache plugin which was not yet

dogpile/cache/region.py

 from __future__ import with_statement
-from dogpile.core import Dogpile, NeedRegenerationException
+from dogpile.core import Lock, NeedRegenerationException
 from dogpile.core.nameregistry import NameRegistry
-
 from .util import function_key_generator, PluginLoader, \
     memoized_property, coerce_string_conf
 from .api import NO_VALUE, CachedValue
 import time
 from functools import wraps
+import threading
 
 _backend_loader = PluginLoader("dogpile.cache")
 register_backend = _backend_loader.register
         else:
             self.backend = backend_cls(arguments or {})
         self.expiration_time = expiration_time
-        self.dogpile_registry = NameRegistry(self._create_dogpile)
         if self.key_mangler is None:
             self.key_mangler = self.backend.key_mangler
+
+        self._lock_registry = NameRegistry(self._create_mutex)
+
         return self
 
-    def _create_dogpile(self, identifier, expiration_time):
-        if expiration_time is None:
-            expiration_time = self.expiration_time
-        return Dogpile(
-                expiration_time,
-                lock=self.backend.get_mutex(identifier)
-            )
+    def _mutex(self, key):
+        return self._lock_registry.get(key)
+
+    class _LockWrapper(object):
+        """weakref-capable wrapper for threading.Lock"""
+        def __init__(self):
+            self.lock = threading.Lock()
+
+        def acquire(self, wait=True):
+            return self.lock.acquire(wait)
+
+        def release(self):
+            self.lock.release()
+
+    def _create_mutex(self, key):
+        mutex = self.backend.get_mutex(key)
+        if mutex is not None:
+            return mutex
+        else:
+            return self._LockWrapper()
 
     def invalidate(self):
         """Invalidate this :class:`.CacheRegion`.
             _config_prefix="%sarguments." % prefix
         )
 
+
     @memoized_property
     def backend(self):
         raise Exception("No backend is configured on this region.")
             self.backend.set(key, value)
             return value.payload, value.metadata["ct"]
 
-        dogpile = self.dogpile_registry.get(key, expiration_time)
-        with dogpile.acquire(gen_value,
-                    value_and_created_fn=get_value) as value:
+        if expiration_time is None:
+            expiration_time = self.expiration_time
+        with Lock(
+                self._mutex(key),
+                gen_value,
+                get_value,
+                expiration_time) as value:
             return value
 
     def _value(self, value):
         """Return a :class:`.CachedValue` given a value."""
         return CachedValue(value, {
-                            "ct":time.time(),
-                            "v":value_version
+                            "ct": time.time(),
+                            "v": value_version
                         })
 
     def set(self, key, value):
       dogpile = dogpile.cache.plugins.mako:MakoPlugin
       """,
       zip_safe=False,
-      install_requires=['dogpile.core>=0.3.0'],
+      install_requires=['dogpile.core>=0.4.0'],
       test_suite='nose.collector',
       tests_require=['nose'],
 )
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.