Mercurial > urweb
annotate caching-tests/test.ur @ 2271:85f91c7452b0
First draft of cache consolidation.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Wed, 21 Oct 2015 09:18:36 -0400 |
parents | f7bc7c11a656 |
children | a3cac6cea625 |
rev | line source |
---|---|
ziv@2213 | 1 table tab : {Id : int, Val : int} PRIMARY KEY Id |
ziv@2203 | 2 |
ziv@2213 | 3 fun cache id = |
ziv@2225 | 4 res <- oneOrNoRows (SELECT tab.Val |
ziv@2225 | 5 FROM tab |
ziv@2225 | 6 WHERE tab.Id = {[id]}); |
ziv@2204 | 7 return <xml><body> |
ziv@2213 | 8 Reading {[id]}. |
ziv@2204 | 9 {case res of |
ziv@2213 | 10 None => <xml>?</xml> |
ziv@2213 | 11 | Some row => <xml>{[row.Tab.Val]}</xml>} |
ziv@2204 | 12 </body></xml> |
ziv@2203 | 13 |
ziv@2269 | 14 fun cache2 id v = |
ziv@2269 | 15 res <- oneOrNoRows (SELECT tab.Val |
ziv@2269 | 16 FROM tab |
ziv@2269 | 17 WHERE tab.Id = {[id]} AND tab.Val = {[v]}); |
ziv@2269 | 18 return <xml><body> |
ziv@2269 | 19 Reading {[id]}. |
ziv@2269 | 20 {case res of |
ziv@2269 | 21 None => <xml>Nope, that's not it.</xml> |
ziv@2269 | 22 | Some _ => <xml>Hooray! You guessed it!</xml>} |
ziv@2269 | 23 </body></xml> |
ziv@2269 | 24 |
ziv@2213 | 25 fun flush id = |
ziv@2239 | 26 dml (UPDATE tab |
ziv@2239 | 27 SET Val = Val * (Id + 2) / Val - 3 |
ziv@2239 | 28 WHERE Id = {[id]} OR Id = {[id - 1]} OR Id = {[id + 1]}); |
ziv@2204 | 29 return <xml><body> |
ziv@2235 | 30 Changed {[id]}! |
ziv@2204 | 31 </body></xml> |
ziv@2234 | 32 |
ziv@2242 | 33 val flush17 = |
ziv@2242 | 34 dml (UPDATE tab |
ziv@2242 | 35 SET Val = Val * (Id + 2) / Val - 3 |
ziv@2242 | 36 WHERE Id = 17); |
ziv@2242 | 37 return <xml><body> |
ziv@2242 | 38 Changed specifically 17! |
ziv@2242 | 39 </body></xml> |
ziv@2242 | 40 |
ziv@2235 | 41 (* fun flush id = *) |
ziv@2235 | 42 (* res <- oneOrNoRows (SELECT tab.Val *) |
ziv@2235 | 43 (* FROM tab *) |
ziv@2235 | 44 (* WHERE tab.Id = {[id]}); *) |
ziv@2235 | 45 (* (case res of *) |
ziv@2235 | 46 (* None => dml (INSERT INTO tab (Id, Val) *) |
ziv@2235 | 47 (* VALUES ({[id]}, 0)) *) |
ziv@2235 | 48 (* | Some row => dml (UPDATE tab *) |
ziv@2235 | 49 (* SET Val = {[row.Tab.Val + 1]} *) |
ziv@2235 | 50 (* WHERE Id = {[id]} OR Id = {[id + 1]})); *) |
ziv@2235 | 51 (* return <xml><body> *) |
ziv@2235 | 52 (* {case res of *) |
ziv@2235 | 53 (* None => <xml>Initialized {[id]}!</xml> *) |
ziv@2235 | 54 (* | Some row => <xml>Incremented {[id]}!</xml>} *) |
ziv@2235 | 55 (* </body></xml> *) |