Mercurial > urweb
annotate caching-tests/test.ur @ 2234:2f7ed04332a0
Progress on LRU cache but still more known bugs to fix.
author | Ziv Scully <ziv@mit.edu> |
---|---|
date | Sun, 28 Jun 2015 12:46:51 -0700 |
parents | 6262dabc08d6 |
children | 0aae15c2a05a |
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@2213 | 14 fun flush id = |
ziv@2225 | 15 res <- oneOrNoRows (SELECT tab.Val |
ziv@2225 | 16 FROM tab |
ziv@2225 | 17 WHERE tab.Id = {[id]}); |
ziv@2221 | 18 (case res of |
ziv@2234 | 19 None => return () (* dml (INSERT INTO tab (Id, Val) *) |
ziv@2234 | 20 (* VALUES ({[id]}, 0)) *) |
ziv@2225 | 21 | Some row => dml (UPDATE tab |
ziv@2225 | 22 SET Val = {[row.Tab.Val + 1]} |
ziv@2234 | 23 WHERE Id = {[id + 1]} OR Id = {[id]} (* OR Id = {[id - 1]} *))); |
ziv@2204 | 24 return <xml><body> |
ziv@2204 | 25 {case res of |
ziv@2213 | 26 None => <xml>Initialized {[id]}!</xml> |
ziv@2213 | 27 | Some row => <xml>Incremented {[id]}!</xml>} |
ziv@2204 | 28 </body></xml> |
ziv@2234 | 29 |
ziv@2234 | 30 (* task periodic 5 = *) |
ziv@2234 | 31 (* fn () => *) |
ziv@2234 | 32 (* t <- now; *) |
ziv@2234 | 33 (* let *) |
ziv@2234 | 34 (* val n = toSeconds t % 2 *) |
ziv@2234 | 35 (* in *) |
ziv@2234 | 36 (* dml (UPDATE tab *) |
ziv@2234 | 37 (* SET Val = 9001 *) |
ziv@2234 | 38 (* WHERE Id = {[n]} OR Id = {[n+1]}) *) |
ziv@2234 | 39 (* end *) |