1
0
Fork 0

use the simple cache

* tekuti/web.scm: Use the cache.
This commit is contained in:
Andy Wingo 2010-12-03 19:59:45 +01:00
parent c099b9532c
commit 83a569885a

View file

@ -26,6 +26,7 @@
(define-module (tekuti web)
#:use-module (web server)
#:use-module (tekuti cache)
#:use-module (tekuti request)
#:use-module (tekuti index)
#:use-module (tekuti page)
@ -57,19 +58,29 @@
((GET debug) page-debug)
(else page-not-found)))
(define (handler request body index)
(define handler
(lambda (request body index cache)
(let ((index (maybe-reindex index)))
(call-with-values (lambda ()
(call-with-values
(lambda ()
(if (cache-hit? cache (car index) request)
(cache-ref cache (car index) request)
(call-with-values
(lambda ()
((choose-handler request) request body (cdr index)))
(lambda (response body)
(values response body index)))))
(sanitize-response request response body)))))
(lambda (response body)
(values response body index
(cache-set cache (car index) request response body)))))))
;; The seemingly useless lambda is to allow for `handler' to be
;; redefined at runtime.
(define (main-loop)
(run-server (lambda (r b i) (handler r b i))
(run-server (lambda (r b i c) (handler r b i c))
*server-impl*
(if (list? *server-impl-args*)
*server-impl-args*
(*server-impl-args*))
(read-index)))
(read-index)
#f))