summaryrefslogtreecommitdiff
path: root/http-cache.tcl
blob: f3777705d2aab23e694c43ae66488e2b16d2950c (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
31
32
33
34
35
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]
		}
    }

	# Process the precache
	foreach i $::http::configure::precache {
		add [string cat $::http::configure::srv $i]
	}

}