Aleš Erjavec avatar Aleš Erjavec committed 1aee9d3

Disabled automatic cache invalidation.

Comments (0)

Files changed (2)

_bioinformatics/obiKEGG/api.py

 from .types import OrganismSummary, Definition, BInfo, Link
 
 
+# A list of all databases with names, abbreviations
 DATABASES = [
     ("KEGG Pathway", "pathway", "path", None),
     ("KEGG Brite", "brite", "br", None),
 
 class KeggApi(object):
     """
-    An abstraction of a kegg api.
+    An abstraction of a rest KEGG API.
     """
 
     def __init__(self):
         Return a list of all available organisms
 
         >>> api.list_organisms()
-        [Definition(entry_id='hsa',...
+        [OrganismSummary(entry_id=T0..
 
         """
         return map(OrganismSummary.from_str,
             # TODO: Invalidate entries by release string.
             for id in ids:
                 key = get.key_from_args((id,))
-                if key not in store:
+                if not get.key_has_valid_cache(key, store):
                     uncached.append(id)
 
         if uncached:
             # in case there are duplicate ids
             uncached = sorted(set(uncached))
+
             rval = KeggApi.get(self, uncached)
 
             if rval is not None:

_bioinformatics/obiKEGG/caching.py

 
     def key_from_args(self, args, kwargs=None):
         key = self.function.__name__ + repr(args)
+        if kwargs is not None:
+            raise NotImplementedError("kwargs are not supported yet")
         return key
 
     def invalidate_key(self, key):
             del store[key]
 
     def last_modified_from_args(self, args, kwargs=None):
-        key = self.key_from_args(args, kwargs)
         if self.instance is not None:
-            self.instance.last_modified(args)
+            return self.instance.last_modified(args)
 
     def invalidate_args(self, args):
         return self.invalidate_key(self.key_from_args(args))
     def __call__(self, *args):
         key = self.key_from_args(args)
         with closing(self.cache_store()) as store:
-            valid = True
-            if key not in store:
-                valid = False
+            if self.key_has_valid_cache(key, store):
+                rval = store[key].value
             else:
-                entry = store[key]
-                rval = entry.value
-
-                if not self.is_entry_valid(entry, args):
-                    valid = False
-            if not valid:
                 rval = self.function(self.instance, *args)
                 store[key] = cache_entry(rval, datetime.now(), None)
 
         return rval
 
-    def min_timestamp(self, args):
-        key = self.key_from_args(args)
-        return datetime.fromtimestamp(0)
+    def key_has_valid_cache(self, key, store):
+        if key not in store:
+            return False
+        else:
+            entry = store[key]
+            return self.is_entry_valid(entry, None)
 
     def is_entry_valid(self, entry, args):
+        # For now always return True, the caching architecture needs to be
+        # completely reworked
+        return True
+
         # Need to check datetime first (it subclasses date)
         if isinstance(entry.mtime, datetime):
             mtime = entry.mtime
         else:
             return False
 
-        if self.min_timestamp(args) > mtime:
-            return False
-
         last_modified = self.last_modified_from_args(args)
 
         if isinstance(last_modified, date):
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.