Commits

zzzeek  committed 5735098

clean up some more

  • Participants
  • Parent commits b1b5386

Comments (0)

Files changed (3)

 
 
     region = make_region(
+        function_key_generator = my_key_generator
+    ).configure(
         "dogpile.cache.dbm",
         expiration_time=300,
         arguments={
             "filename":"file.dbm"
-        },
-        function_key_generator = my_key_generator
-
+        }
     )
 
 ``key_mangler``

File dogpile/cache/region.py

 from dogpile import Dogpile, NeedRegenerationException
-from dogpile.cache.util import function_key_generator, PluginLoader
+from dogpile.cache.util import function_key_generator, PluginLoader, memoized_property
 from dogpile.cache.api import NO_VALUE, CachedValue
 import time
 
          backend.  Is typically a dict.
          
         """
+        if "backend" in self.__dict__:
+            raise Exception(
+                    "This region is already "
+                    "configured with the %s backend" 
+                    % self.backend)
         backend_cls = _backend_loader.load(backend)
         if _config_argument_dict:
             self.backend = backend_cls.from_config_dict(
             _config_prefix="%s.arguments" % prefix
         )
 
+    @memoized_property
+    def backend(self):
+        raise Exception("No backend is configured on this region.")
+
     def get(self, key):
         """Return a value from the cache, based on the given key.
 

File dogpile/cache/util.py

             return mangler(key)
         else:
             return key
-    return mangle
+    return mangle
+
+class memoized_property(object):
+    """A read-only @property that is only evaluated once."""
+    def __init__(self, fget, doc=None):
+        self.fget = fget
+        self.__doc__ = doc or fget.__doc__
+        self.__name__ = fget.__name__
+
+    def __get__(self, obj, cls):
+        if obj is None:
+            return self
+        obj.__dict__[self.__name__] = result = self.fget(obj)
+        return result