annotate 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
rev   line source
ziv@2203 1 table foo01 : {Id : int, Bar : string} PRIMARY KEY Id
ziv@2203 2 table foo10 : {Id : int, Bar : string} PRIMARY KEY Id
ziv@2213 3 table tab : {Id : int, Val : int} PRIMARY KEY Id
ziv@2203 4
ziv@2213 5 fun cache01 () =
ziv@2213 6 res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
ziv@2213 7 return <xml><body>
ziv@2213 8 Reading 1.
ziv@2213 9 {case res of
ziv@2213 10 None => <xml>?</xml>
ziv@2213 11 | Some row => <xml>{[row.Foo01.Bar]}</xml>}
ziv@2213 12 </body></xml>
ziv@2213 13
ziv@2213 14 fun cache10 () =
ziv@2213 15 res <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
ziv@2213 16 return <xml><body>
ziv@2213 17 Reading 2.
ziv@2213 18 {case res of
ziv@2213 19 None => <xml>?</xml>
ziv@2213 20 | Some row => <xml>{[row.Foo10.Bar]}</xml>}
ziv@2213 21 </body></xml>
ziv@2213 22
ziv@2213 23 fun cache11 () =
ziv@2213 24 res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42);
ziv@2213 25 bla <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42);
ziv@2213 26 return <xml><body>
ziv@2213 27 Reading 1 and 2.
ziv@2213 28 {case res of
ziv@2213 29 None => <xml>?</xml>
ziv@2213 30 | Some row => <xml>{[row.Foo01.Bar]}</xml>}
ziv@2213 31 {case bla of
ziv@2213 32 None => <xml>?</xml>
ziv@2213 33 | Some row => <xml>{[row.Foo10.Bar]}</xml>}
ziv@2213 34 </body></xml>
ziv@2213 35
ziv@2213 36 fun flush01 () =
ziv@2204 37 dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42);
ziv@2204 38 return <xml><body>
ziv@2204 39 Flushed 1!
ziv@2204 40 </body></xml>
ziv@2203 41
ziv@2213 42 fun flush10 () =
ziv@2204 43 dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42);
ziv@2204 44 return <xml><body>
ziv@2204 45 Flushed 2!
ziv@2204 46 </body></xml>
ziv@2203 47
ziv@2213 48 fun flush11 () =
ziv@2204 49 dml (UPDATE foo01 SET Bar = "baz11" WHERE Id = 42);
ziv@2204 50 dml (UPDATE foo10 SET Bar = "baz11" WHERE Id = 42);
ziv@2204 51 return <xml><body>
ziv@2204 52 Flushed 1 and 2!
ziv@2204 53 </body></xml>
ziv@2203 54
ziv@2213 55 fun cache id =
ziv@2213 56 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
ziv@2204 57 return <xml><body>
ziv@2213 58 Reading {[id]}.
ziv@2204 59 {case res of
ziv@2213 60 None => <xml>?</xml>
ziv@2213 61 | Some row => <xml>{[row.Tab.Val]}</xml>}
ziv@2204 62 </body></xml>
ziv@2203 63
ziv@2213 64 fun flush id =
ziv@2213 65 res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]});
ziv@2213 66 dml (case res of
ziv@2213 67 None => (INSERT INTO tab (Id, Val) VALUES ({[id]}, 0))
ziv@2213 68 | Some row => (UPDATE tab SET Val = {[row.Tab.Val + 1]} WHERE Id = {[id]}));
ziv@2204 69 return <xml><body>
ziv@2213 70 (* Flushed {[id]}! *)
ziv@2204 71 {case res of
ziv@2213 72 None => <xml>Initialized {[id]}!</xml>
ziv@2213 73 | Some row => <xml>Incremented {[id]}!</xml>}
ziv@2204 74 </body></xml>