From d4281d826e9d78de49b16d996ca5dbfab70289a2 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 3 Mar 2014 22:34:49 -0800 Subject: [PATCH] require reload working --- cache.rkt | 4 +++- render.rkt | 15 +++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/cache.rkt b/cache.rkt index 7664024..7c0af82 100644 --- a/cache.rkt +++ b/cache.rkt @@ -4,7 +4,7 @@ ;; The cache is a hash with paths as keys. ;; The cache values are also hashes, with key/value pairs for that path. -(provide current-cache make-cache cached-require cache-ref) +(provide reset-cache current-cache make-cache cached-require cache-ref) ;; Don't initialize a cache when the module is loaded. This induces reliance. ;; The cache only makes sense if a single one is used across a whole session (e.g., via parameterize). @@ -12,6 +12,8 @@ (define (make-cache) (make-hash)) +(define (reset-cache) (hash-clear! (current-cache))) + (define (->complete-path path-string) (path->complete-path (if (string? path-string) (string->path path-string) path-string))) diff --git a/render.rkt b/render.rkt index 94beb30..5ea7898 100644 --- a/render.rkt +++ b/render.rkt @@ -70,21 +70,20 @@ (define (project-requires-changed?) - (define changed? (ormap file-needs-rerequire? (get-project-require-files))) + (define changed? (ormap (λ(x) x) (map file-needed-rerequire? (get-project-require-files)))) ; make sure all files are rerequired before test (when changed? (begin - (message "render: project requires have changed, resetting cache") - (current-cache (make-cache)) - ;; also need to dirty up the mod-dates table so existing files are deemed invalid - (reset-modification-dates))) + (message "render: project requires have changed, resetting cache & file-modification table") + (reset-cache) + (reset-modification-dates))) ; mark existing files as obsolete changed?) (define/contract (render-needed? source-path template-path output-path) (complete-path? (or/c #f complete-path?) complete-path? . -> . boolean?) (or (not (file-exists? output-path)) - (report (modification-date-expired? source-path template-path)) - (and (not (null-source? source-path)) (file-needs-rerequire? source-path)) + (modification-date-expired? source-path template-path) + (and (not (null-source? source-path)) (file-needed-rerequire? source-path)) (project-requires-changed?))) @@ -174,7 +173,7 @@ (build-path (world:current-server-extras-path) world:fallback-template)))) ; fallback template -(define/contract (file-needs-rerequire? source-path) +(define/contract (file-needed-rerequire? source-path) (complete-path? . -> . boolean?) (define-values (source-dir source-name _) (split-path source-path)) ;; use dynamic-rerequire now to force render for cached-require later,