import vim

from taskwiki.task import VimwikiTask

class TaskCache(object):
    """
    A cache that holds all the tasks in the given file and prevents
    multiple redundant taskwarrior calls.
    """

    def __init__(self, tw):
        self.cache = dict()
        self.tw = tw

    def __getitem__(self, key):
        task = self.cache.get(key)

        if task is None:
            task = VimwikiTask(vim.current.buffer[key], key, self.tw, self)
            self.cache[key] = task

        return task

    def __iter__(self):
#        iterated_cache = {
        while self.cache.keys():
            for key in list(self.cache.keys()):
                task = self.cache[key]
                if all([t.line_number not in self.cache.keys()
                        for t in task.add_dependencies]):
                    del self.cache[key]
                    yield task

    def reset(self):
        self.cache = dict()

#    def update_tasks(self):
#        tasks = [t


@@ -1,12 +1,24 @@
+import copy%0A
 import vim%0A%0A
@@ -56,16 +56,17 @@
 kiTask%0A%0A
+%0A
 class Ta
@@ -237,16 +237,49 @@
 f, tw):%0A
+        self.uuid_cache = dict()%0A
         
@@ -521,24 +521,101 @@
 ey%5D = task%0A%0A
+            if task.uuid:%0A                self.uuid_cache%5Btask.uuid%5D = task%0A%0A
         retu
@@ -639,33 +639,32 @@
 __iter__(self):%0A
-#
         iterated
@@ -676,9 +676,29 @@
 e = 
-%7B
+copy.copy(self.cache)
 %0A   
@@ -708,21 +708,25 @@
   while 
-self.
+iterated_
 cache.ke
@@ -759,21 +759,25 @@
 in list(
-self.
+iterated_
 cache.ke
@@ -802,29 +802,33 @@
      task = 
-self.
+iterated_
 cache%5Bkey%5D%0A 
@@ -871,21 +871,25 @@
  not in 
-self.
+iterated_
 cache.ke
@@ -975,21 +975,25 @@
     del 
-self.
+iterated_
 cache%5Bke

Index tasks by uuid as well as line number