caching for lines and stations (saved as json)
[pywienerlinien] / gotovienna / cache.py
index edb6677..eae95b1 100644 (file)
@@ -29,10 +29,10 @@ class Lines(dict):
     def __init__(self):
         self.load()
 
-    def update(self, *args, **kwargs):
-        a = dict.update(self, *args, **kwargs)
+    def __setitem__(self, *args, **kwargs):
+        s = dict.__setitem__(self, *args, **kwargs)
         self.save()
-        return a
+        return s
 
     def save(self):
         with open(defaults.cache_lines, 'w') as fp:
@@ -45,7 +45,6 @@ class Lines(dict):
 
 lines = Lines()
 
-
 class Stations(dict):
     stations = None
 
@@ -63,10 +62,9 @@ class Stations(dict):
         # FIXME maybe cause problems in the future, race conditions
         Stations.stations[line] = self
 
-    def update(self, *args, **kwargs):
-        u = dict.update(self, *args, **kwargs)
-        if args[0]:
-            Stations.save()
+    def __setitem__(self, *args, **kwargs):
+        u = dict.__setitem__(self, *args, **kwargs)
+        Stations.save()
         return u
 
     @classmethod