summaryrefslogtreecommitdiff
path: root/http-cache.tcl
diff options
context:
space:
mode:
authoralekseiplusplus <alekseijeaves@protonmail.com>2024-06-29 20:27:11 +1000
committeralekseiplusplus <alekseijeaves@protonmail.com>2024-06-29 20:27:11 +1000
commita61f03cfbf62eb006e6bd845694f18d40101d4e8 (patch)
tree30c7a00c956e61ed2c54c4893cb449eae5bf55da /http-cache.tcl
parent252ad2b3446457e95fb7bb41829bc24304090232 (diff)
Added cache
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]
+ }
+
+}