1 ! Copyright (C) 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar db.tuples db.types http.server.filters
4 kernel math.intervals random ;
7 TUPLE: server-state id expires ;
9 : new-server-state ( id class -- server-state )
10 new swap >>id ; inline
14 { "id" "ID" +random-id+ system-random-generator }
15 { "expires" "EXPIRES" BIG-INTEGER +not-null+ }
18 : get-state ( id class -- state )
19 new-server-state select-tuple ;
21 : expire-state ( class -- )
23 -1/0. now timestamp>micros [a,b] >>expires
26 TUPLE: server-state-manager < filter-responder timeout ;
28 : new-server-state-manager ( responder class -- responder' )
31 20 minutes >>timeout ; inline
33 : touch-state ( state manager -- )
34 timeout>> hence timestamp>micros >>expires drop ;