]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/dns/cache/nx/nx.factor
292e5f15b52fb881c92541f85ee8662fdc6688a8
[factor.git] / unmaintained / dns / cache / nx / nx.factor
1
2 USING: kernel assocs locals combinators
3        math math.functions system unicode ;
4
5 IN: dns.cache.nx
6
7 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
8
9 : nx-cache ( -- table ) H{ } ;
10
11 : nx-cache-at        (      name -- time ) >lower nx-cache at        ;
12 : nx-cache-delete-at (      name --      ) >lower nx-cache delete-at ;
13 : nx-cache-set-at    ( time name --      ) >lower nx-cache set-at    ;
14
15 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16
17 : now ( -- seconds ) millis 1000.0 / round >integer ;
18
19 :: non-existent-name? ( NAME -- ? )
20    [let | TIME [ NAME nx-cache-at ] |
21      {
22        { [ TIME f    = ] [                         f ] }
23        { [ TIME now <= ] [ NAME nx-cache-delete-at f ] }
24        { [ t           ] [                         t ] }
25      }
26      cond
27    ] ;
28
29 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30
31 :: cache-non-existent-name ( NAME TTL -- )
32    [let | TIME [ TTL now + ] | TIME NAME nx-cache-set-at ] ;
33
34 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
35