summaryrefslogtreecommitdiff
path: root/http-cache.tcl
blob: ee5898130b4c7345b4ff9d0afc67b946a26e4ca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
namespace eval cache {

    # Dictionary containing filename and contents pairs.
    variable cache {};
    
    proc hit {filename} {
		variable cache
		return [dict exists $cache $filename]
	}

	proc get {filename} {
		variable cache
		return [dict get $cache $filename]
	}

    proc add {filename} {
		variable cache
		set file [open $filename]
		fconfigure $file -translation binary
		dict append cache $filename [read $file]
    }

    proc remove {filename} {
		variable cache
		if [dict exists $cache $filename] {
			set cache [dict remove $cache $filename]
		}
    }

}