Commits

Chris Mutel committed 11c9653

Cache can be a simple directory

Comments (0)

Files changed (2)

brightway2/_config.py

 import tempfile
 
 
-class Cache(object):
-    def __init__(self, use_me):
-        self.use = use_me
-        self.data = {}
-
-    def __getitem__(self, key):
-        if not self.use:
-            return False
-        return self.data[key]
-
-    def __setitem__(self, key, value):
-        if not self.use:
-            return False
-        else:
-            self.data[key] = value
-            return True
-
-    def __contains__(self, key):
-        return self.use and key in self.data
-
-
 class Config(object):
     """A singleton that store configuration settings. Default data directory is ``brightway`` in the user's home directory, and is stored as ``config.dir``. Other configuration settings can also be assigned as needed.
 
     def __init__(self, path=None):
         self.is_temp_dir = False
         self.reset(path)
-        self.cache = Cache(self.p["use_cache"])
+        self.cache = {}
 
     def check_dir(self, dir=None):
         """Check is directory is writeable."""

brightway2/database.py

         """
         if self.database not in databases:
             raise UnknownObject("This database is not yet registered")
-        if version == None and config.p["use_cache"] and \
+        if version == None and config.p.get("use_cache", False) and \
                 self.database in config.cache:
             return config.cache[self.database]
         try:
             data = pickle.load(open(os.path.join(config.dir, "intermediate",
                 self.filename(version)), "rb"))
-            if version == None and config.p["use_cache"]:
+            if version == None and config.p.get("use_cache", False):
                 config.cache[self.database] = data
             return data
         except OSError: