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) (define-module (tekuti web)
#:use-module (web server) #:use-module (web server)
#:use-module (tekuti cache)
#:use-module (tekuti request) #:use-module (tekuti request)
#:use-module (tekuti index) #:use-module (tekuti index)
#:use-module (tekuti page) #:use-module (tekuti page)
@ -57,19 +58,29 @@
((GET debug) page-debug) ((GET debug) page-debug)
(else page-not-found))) (else page-not-found)))
(define (handler request body index) (define handler
(let ((index (maybe-reindex index))) (lambda (request body index cache)
(call-with-values (lambda () (let ((index (maybe-reindex index)))
((choose-handler request) request body (cdr index))) (call-with-values
(lambda (response body) (lambda ()
(values response body index))))) (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)
(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 ;; The seemingly useless lambda is to allow for `handler' to be
;; redefined at runtime. ;; redefined at runtime.
(define (main-loop) (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* *server-impl*
(if (list? *server-impl-args*) (if (list? *server-impl-args*)
*server-impl-args* *server-impl-args*
(*server-impl-args*)) (*server-impl-args*))
(read-index))) (read-index)
#f))