From ce0ebf2349e021003828542fce0b2642753bbff7 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 29 Oct 2018 17:13:52 -0700 Subject: [PATCH] cache --- pollen/cache.rkt | 31 +++++++++++++++++-------------- pollen/private/ts.rktd | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/pollen/cache.rkt b/pollen/cache.rkt index a7a88ec..ceaa582 100644 --- a/pollen/cache.rkt +++ b/pollen/cache.rkt @@ -18,21 +18,24 @@ (raise-argument-error 'reset-cache "path-string to existing directory" starting-dir)) (for ([path (in-directory starting-dir)] #:when (cache-directory? path)) - (message (format "removing cache directory: ~a" path)) - (delete-directory/files path))) + (message (format "removing cache directory: ~a" path)) + (delete-directory/files path))) + +(define ((path-error-handler caller-name path-or-path-string) e) + (raise-argument-error caller-name "valid path or path-string" path-or-path-string)) (define-namespace-anchor cache-module-ns) + (define cached-require-base (let ([ram-cache (make-hash)]) (λ (path-or-path-string subkey caller-name) - (define path (with-handlers ([exn:fail? (λ (e) (raise-argument-error caller-name "valid path or path-string" path-or-path-string))]) - (path->complete-path (if (path? path-or-path-string) - path-or-path-string - (string->path path-or-path-string))))) - + (define path + (with-handlers ([exn:fail? (path-error-handler caller-name path-or-path-string)]) + (path->complete-path (if (path? path-or-path-string) + path-or-path-string + (string->path path-or-path-string))))) (unless (file-exists? path) (raise-argument-error caller-name "path to existing file" path-or-path-string)) - (cond [(setup:compile-cache-active path) (define key (paths->key path)) @@ -40,18 +43,18 @@ (define (get-cache-record) (cache-ref! key convert-path-to-cache-record)) (define ram-cache-record (hash-ref! ram-cache key get-cache-record)) (hash-ref ram-cache-record subkey)] - [else (parameterize ([current-namespace (make-base-namespace)]) - (namespace-attach-module (namespace-anchor->namespace cache-module-ns) 'pollen/setup) ; brings in params - (dynamic-require path subkey))])))) - + [else + (parameterize ([current-namespace (make-base-namespace)]) + (namespace-attach-module + (namespace-anchor->namespace cache-module-ns) + 'pollen/setup (current-namespace)) ; brings in currently instantiated params (unlike namespace-require) + (dynamic-require path subkey))])))) (define+provide (cached-require path-string subkey) (cached-require-base path-string subkey 'cached-require)) - (define+provide (cached-doc path-string) (cached-require-base path-string (setup:main-export) 'cached-doc)) - (define+provide (cached-metas path-string) (cached-require-base path-string (setup:meta-export) 'cached-metas)) \ No newline at end of file diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 935c68b..9a45b08 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1540858428 +1540858431