diff caching-tests/test.ur @ 2213:365727ff68f4

Complete overhaul: cache queries based on immediate query result, not eventual HTML output.
author Ziv Scully <ziv@mit.edu>
date Tue, 14 Oct 2014 18:05:09 -0400
parents 0ca11d57c175
children 639e62ca2530
line wrap: on
line diff
--- a/caching-tests/test.ur	Mon Sep 15 20:01:16 2014 -0400
+++ b/caching-tests/test.ur	Tue Oct 14 18:05:09 2014 -0400
@@ -1,52 +1,74 @@
 table foo01 : {Id : int, Bar : string} PRIMARY KEY Id
 table foo10 : {Id : int, Bar : string} PRIMARY KEY Id
+table tab : {Id : int, Val : int} PRIMARY KEY Id
 
-fun flush01 () : transaction page =
+fun cache01 () =
+    res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
+    return <xml><body>
+      Reading 1.
+      {case res of
+           None => <xml>?</xml>
+         | Some row => <xml>{[row.Foo01.Bar]}</xml>}
+    </body></xml>
+
+fun cache10 () =
+    res <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
+    return <xml><body>
+      Reading 2.
+      {case res of
+           None => <xml>?</xml>
+         | Some row => <xml>{[row.Foo10.Bar]}</xml>}
+    </body></xml>
+
+fun cache11 () =
+    res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
+    bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
+    return <xml><body>
+      Reading 1 and 2.
+      {case res of
+           None => <xml>?</xml>
+         | Some row => <xml>{[row.Foo01.Bar]}</xml>}
+      {case bla of
+           None => <xml>?</xml>
+         | Some row => <xml>{[row.Foo10.Bar]}</xml>}
+    </body></xml>
+
+fun flush01 () =
     dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42);
     return <xml><body>
       Flushed 1!
     </body></xml>
 
-fun flush10 () : transaction page =
+fun flush10 () =
     dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42);
     return <xml><body>
       Flushed 2!
     </body></xml>
 
-fun flush11 () : transaction page =
+fun flush11 () =
     dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42);
     dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42);
     return <xml><body>
       Flushed 1 and 2!
     </body></xml>
 
-fun cache01 () : transaction page =
-    res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
+fun cache id =
+    res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
     return <xml><body>
-      Reading 1.
+      Reading {[id]}.
       {case res of
-           None => <xml></xml>
-         | Some row => <xml>{[row.Foo01.Bar]}</xml>}
+           None => <xml>?</xml>
+         | Some row => <xml>{[row.Tab.Val]}</xml>}
     </body></xml>
 
-fun cache10 () : transaction page =
-    res <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
+fun flush id =
+    res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
+    dml (case res of
+             None => (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0))
+           | Some row => (UPDATE tab SET Val = {[row.Tab.Val + 1]} WHERE Id = {[id]}));
     return <xml><body>
-      Reading 2.
+      (* Flushed {[id]}! *)
       {case res of
-           None => <xml></xml>
-         | Some row => <xml>{[row.Foo10.Bar]}</xml>}
+           None => <xml>Initialized {[id]}!</xml>
+         | Some row => <xml>Incremented {[id]}!</xml>}
     </body></xml>
-
-fun cache11 () : transaction page =
-    res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
-    bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
-    return <xml><body>
-      Reading 1 and 2.
-      {case res of
-           None => <xml></xml>
-         | Some row => <xml>{[row.Foo01.Bar]}</xml>}
-      {case bla of
-           None => <xml></xml>
-         | Some row => <xml>{[row.Foo10.Bar]}</xml>}
-    </body></xml>