summaryrefslogtreecommitdiff
path: root/http-cache.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'http-cache.tcl')
-rwxr-xr-xhttp-cache.tcl35
1 files changed, 35 insertions, 0 deletions
diff --git a/http-cache.tcl b/http-cache.tcl
new file mode 100755
index 0000000..25e5f0d
--- /dev/null
+++ b/http-cache.tcl
@@ -0,0 +1,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]
+ }
+ }
+
+ #TODO: Pre-cache all precache files.
+ foreach i $precache {
+ add [string cat $::http::root $i]
+ }
+
+}