diff options
author | Ziv Scully <ziv@mit.edu> | 2014-10-14 18:05:09 -0400 |
---|---|---|
committer | Ziv Scully <ziv@mit.edu> | 2014-10-14 18:05:09 -0400 |
commit | 75d1eedd15edc41b1c2bc9d1fce7a74f37bd78a1 (patch) | |
tree | 09a958bb9333b12cc118b14053cb9043e8a6463b /caching-tests | |
parent | 8cf3a275f25ffcbb97d623c4e988fdcc81ef5978 (diff) |
Complete overhaul: cache queries based on immediate query result, not eventual HTML output.
Diffstat (limited to 'caching-tests')
-rw-r--r-- | caching-tests/test.db | bin | 3072 -> 5120 bytes | |||
-rw-r--r-- | caching-tests/test.sql | 7 | ||||
-rw-r--r-- | caching-tests/test.ur | 74 | ||||
-rw-r--r-- | caching-tests/test.urp | 1 | ||||
-rw-r--r-- | caching-tests/test.urs | 2 |
5 files changed, 57 insertions, 27 deletions
diff --git a/caching-tests/test.db b/caching-tests/test.db Binary files differindex a5c91e8f..944aa851 100644 --- a/caching-tests/test.db +++ b/caching-tests/test.db diff --git a/caching-tests/test.sql b/caching-tests/test.sql index 862245b7..efa271ec 100644 --- a/caching-tests/test.sql +++ b/caching-tests/test.sql @@ -8,4 +8,9 @@ CREATE TABLE uw_Test_foo01(uw_id integer NOT NULL, uw_bar text NOT NULL, ); -
\ No newline at end of file + CREATE TABLE uw_Test_tab(uw_id integer NOT NULL, uw_val integer NOT NULL, + PRIMARY KEY (uw_id) + + ); + +
\ No newline at end of file diff --git a/caching-tests/test.ur b/caching-tests/test.ur index a99a387b..cb391da7 100644 --- a/caching-tests/test.ur +++ b/caching-tests/test.ur @@ -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 = - dml (UPDATE foo01 SET Bar = "baz01" WHERE Id = 42); - return <xml><body> - Flushed 1! - </body></xml> - -fun flush10 () : transaction page = - dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42); - return <xml><body> - Flushed 2! - </body></xml> - -fun flush11 () : transaction page = - 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 = +fun cache01 () = res <- oneOrNoRows (SELECT foo01.Bar FROM foo01 WHERE foo01.Id = 42); return <xml><body> Reading 1. {case res of - None => <xml></xml> + None => <xml>?</xml> | Some row => <xml>{[row.Foo01.Bar]}</xml>} </body></xml> -fun cache10 () : transaction page = +fun cache10 () = res <- oneOrNoRows (SELECT foo10.Bar FROM foo10 WHERE foo10.Id = 42); return <xml><body> Reading 2. {case res of - None => <xml></xml> + None => <xml>?</xml> | Some row => <xml>{[row.Foo10.Bar]}</xml>} </body></xml> -fun cache11 () : transaction page = +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> + None => <xml>?</xml> | Some row => <xml>{[row.Foo01.Bar]}</xml>} {case bla of - None => <xml></xml> + 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 () = + dml (UPDATE foo10 SET Bar = "baz10" WHERE Id = 42); + return <xml><body> + Flushed 2! + </body></xml> + +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 cache id = + res <- oneOrNoRows (SELECT tab.Val FROM tab WHERE tab.Id = {[id]}); + return <xml><body> + Reading {[id]}. + {case res of + None => <xml>?</xml> + | Some row => <xml>{[row.Tab.Val]}</xml>} + </body></xml> + +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> + (* Flushed {[id]}! *) + {case res of + None => <xml>Initialized {[id]}!</xml> + | Some row => <xml>Incremented {[id]}!</xml>} + </body></xml> diff --git a/caching-tests/test.urp b/caching-tests/test.urp index 123f58e5..7ac469f9 100644 --- a/caching-tests/test.urp +++ b/caching-tests/test.urp @@ -3,5 +3,6 @@ sql test.sql safeGet Test/flush01 safeGet Test/flush10 safeGet Test/flush11 +safeGet Test/flush test diff --git a/caching-tests/test.urs b/caching-tests/test.urs index ce7d0350..ace4ba28 100644 --- a/caching-tests/test.urs +++ b/caching-tests/test.urs @@ -4,3 +4,5 @@ val cache11 : unit -> transaction page val flush01 : unit -> transaction page val flush10 : unit -> transaction page val flush11 : unit -> transaction page +val cache : int -> transaction page +val flush : int -> transaction page |