 
 (declare make-reaction)
 
-(defn- cached-reaction [f key obj destroy]
-  (if-some [r (get cached-reactions key)]
-    (-deref r)
-    (if-not (nil? *ratom-context*)
-      (let [r (make-reaction
-               f :on-dispose (fn [x]
-                               (set! cached-reactions
-                                     (dissoc cached-reactions key))
-                               (when-not (nil? obj)
-                                 (set! (.-reaction obj) nil))
-                               (when-not (nil? destroy)
-                                 (destroy x))
-                               nil))
-            v (-deref r)]
-        (set! cached-reactions (assoc cached-reactions key r))
-        (when-not (nil? obj)
-          (set! (.-reaction obj) r))
-        v)
-      (f))))
-
-(deftype Track [f key ^:mutable reaction]
+(defonce cached-reactions (transient {}))
+
+(defn- cached-reaction [f k1 k2 obj destroy]
+  (let [m (if-some [v (get cached-reactions k1)]
+            v
+            (let [newm (transient {})]
+              (assoc! cached-reactions k1 newm)
+              newm))]
+    (if-some [r (get m k2)]
+      (-deref r)
+      (if-not (nil? *ratom-context*)
+        (let [r (make-reaction
+                 f :on-dispose (fn [x]
+                                 (when debug (swap! -running dec))
+                                 (let [m (get cached-reactions k1)]
+                                   (->> (dissoc! m k2)
+                                        (assoc! cached-reactions k1)
+                                        (set! cached-reactions)))
+                                 (when-not (nil? obj)
+                                   (set! (.-reaction obj) nil))
+                                 (when-not (nil? destroy)
+                                   (destroy x))
+                                 nil))
+              v (-deref r)]
+          (->> (assoc! m k2 r)
+               (assoc! cached-reactions k1)
+               (set! cached-reactions))
+          (when debug (swap! -running inc))
+          (when-not (nil? obj)
+            (set! (.-reaction obj) r))
+          v)
+        (f)))))
+
+(deftype Track [f args ^:mutable reaction]
   IReactiveAtom
 
   IDeref
   (-deref [this]
     (if-some [r reaction]
       (-deref r)
-      (cached-reaction f key this nil)))
+      (cached-reaction #(apply f args) f args this nil)))
 
   IEquiv
   (-equiv [_ other]

  (-pr-writer [a w opts] (pr-atom a w opts "Track:")))

(defn make-track [f args]
  (Track. #(apply f args) [f args] nil))

(defn make-track! [f args]
  (let [t (make-track f args)


(defn with-let-values [key]
  (if-some [c *ratom-context*]
    (cached-reaction array key (reaction-key c)
                     nil with-let-destroy)
    (array)))

