get thunky

pull/218/head
Matthew Butterick 5 years ago
parent 2f663e4bf3
commit 16c11c6cda

@ -1 +1 @@
1581031670 1581033338

@ -55,12 +55,11 @@
[pcjs null]) [pcjs null])
([source-path (in-list source-paths-in)]) ([source-path (in-list source-paths-in)])
(match (let/ec exit (match (let/ec exit
(define exiter (λ () (exit 'cache-miss)))
(define output-path (or (->output-path source-path) #false)) (define output-path (or (->output-path source-path) #false))
(define template-path (define template-path
(cache-ref! (template-cache-key source-path output-path) exiter)) (cache-ref! (template-cache-key source-path output-path) (λ () (exit 'template-miss))))
(render-to-file-if-needed source-path template-path output-path exiter)) (render-to-file-if-needed source-path template-path output-path (λ () (exit 'render-miss))))
['cache-miss (values (cons source-path usps) pcjs)] [(? symbol? sym) (values (cons source-path usps) pcjs)]
[_ (values usps (cons (cons source-path #true) pcjs))]))) [_ (values usps (cons (cons source-path #true) pcjs))])))
(define job-count (define job-count
@ -208,7 +207,7 @@
[(and sp op) (render-to-file-if-needed sp #false op)] [(and sp op) (render-to-file-if-needed sp #false op)]
[(pagetree-source? so-path) (render-pagenodes so-path)])) [(pagetree-source? so-path) (render-pagenodes so-path)]))
(define render-ram-cache (make-hash)) (define ram-cache (make-hash))
;; note that output and template order is reversed from typical ;; note that output and template order is reversed from typical
(define (render-to-file-base caller (define (render-to-file-base caller
@ -241,16 +240,17 @@
(cond (cond
[render-cache-activated? [render-cache-activated?
(define key (paths->key 'output source-path template-path output-path)) (define key (paths->key 'output source-path template-path output-path))
(hash-ref! render-ram-cache (hash-ref! ram-cache
;; within a session, this will prevent repeat players like "template.html.p" ;; within a session, this will prevent repeat players like "template.html.p"
;; from hitting the file cache repeatedly ;; from hitting the file cache repeatedly
key key
(λ ()
(cache-ref! key (cache-ref! key
render-thunk render-thunk
#:notify-cache-use #:notify-cache-use
(λ (str) (λ (str)
(message (format "from cache /~a" (message (format "from cache /~a"
(find-relative-path (current-project-root) output-path))))))] (find-relative-path (current-project-root) output-path)))))))]
[else (render-thunk)])) [else (render-thunk)]))
(unless (current-null-output?) (unless (current-null-output?)
(display-to-file render-result (display-to-file render-result
@ -404,7 +404,6 @@
(build-path (current-server-extras-path) (build-path (current-server-extras-path)
(add-ext (setup:fallback-template-prefix source-path) output-path-ext)))) (add-ext (setup:fallback-template-prefix source-path) output-path-ext))))
(define template-ram-cache (make-hash))
(define (template-cache-key source-path output-path) (define (template-cache-key source-path output-path)
(paths->key 'template source-path (current-poly-target) output-path)) (paths->key 'template source-path (current-poly-target) output-path))
@ -415,10 +414,11 @@
[(->output-path source-path)] [(->output-path source-path)]
[else #false])) [else #false]))
(define key (template-cache-key source-path output-path)) (define key (template-cache-key source-path output-path))
(hash-ref! template-ram-cache (hash-ref! ram-cache
;; within a session, this will prevent repeat players like "template.html.p" ;; within a session, this will prevent repeat players like "template.html.p"
;; from hitting the file cache repeatedly ;; from hitting the file cache repeatedly
key key
(λ ()
(cache-ref! key (cache-ref! key
(λ () (λ ()
(match source-path (match source-path
@ -432,7 +432,7 @@
get-default-template get-default-template
get-fallback-template)]) get-fallback-template)])
(file-exists-or-has-source? (proc source-path output-path-ext)))] (file-exists-or-has-source? (proc source-path output-path-ext)))]
[_ #false]))))) [_ #false]))))))
(module-test-external (module-test-external
(require pollen/setup sugar/file sugar/coerce) (require pollen/setup sugar/file sugar/coerce)

Loading…
Cancel
Save