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