summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Andy Wingo2010-12-03 19:59:45 +0100
committerGravatar Andy Wingo2010-12-03 19:59:45 +0100
commit83a569885af47706e64066f5cddf1b7a2bf293a9 (patch)
treea25c0cfcdc56ad6c073b594effb2e0e9fd677151
parentc099b9532c890a1e4bdbe79cbf320c36ad3c30d3 (diff)
downloadtekuti-83a569885af47706e64066f5cddf1b7a2bf293a9.tar.gz
tekuti-83a569885af47706e64066f5cddf1b7a2bf293a9.zip
use the simple cache
* tekuti/web.scm: Use the cache.
-rw-r--r--tekuti/web.scm27
1 files changed, 19 insertions, 8 deletions
diff --git a/tekuti/web.scm b/tekuti/web.scm
index 31ef42b..a6fad73 100644
--- a/tekuti/web.scm
+++ b/tekuti/web.scm
@@ -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)
- (let ((index (maybe-reindex index)))
- (call-with-values (lambda ()
- ((choose-handler request) request body (cdr index)))
- (lambda (response body)
- (values response body index)))))
+(define handler
+ (lambda (request body index cache)
+ (let ((index (maybe-reindex index)))
+ (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)
+ (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))