add file-based cache (addresses issue #25)

pull/27/head
Matthew Butterick 10 years ago
parent 5cc426d9f7
commit 0e1716827e

@ -1,16 +1,27 @@
#lang racket/base
(require racket/rerequire "world.rkt")
(require racket/rerequire racket/serialize racket/file "world.rkt")
;; The cache is a hash with paths as keys.
;; The cache values are also hashes, with key/value pairs for that path.
(provide reset-cache current-cache make-cache cached-require cache-ref)
(define (make-cache) (make-hash))
(define (get-cache-file-path)
(build-path (world:current-project-root) world:cache-filename))
(define (make-cache)
(define cache-file-path (get-cache-file-path))
(if (file-exists? cache-file-path)
(deserialize (file->value cache-file-path))
(make-hash)))
(define current-cache (make-parameter (make-cache)))
(define (reset-cache) (hash-clear! (current-cache)))
(define (reset-cache)
(define cache-path (get-cache-file-path))
(when (file-exists? cache-path)
(delete-file cache-path))
(current-cache (make-cache)))
(define (->complete-path path-string)
(path->complete-path (if (string? path-string) (string->path path-string) path-string)))
@ -28,6 +39,7 @@
(hash-set! cache-hash 'mod-time (file-or-directory-modify-seconds path))
(hash-set! cache-hash world:main-pollen-export (dynamic-require path world:main-pollen-export))
(hash-set! cache-hash world:meta-pollen-export (dynamic-require path world:meta-pollen-export))
(write-to-file (serialize (current-cache)) (get-cache-file-path) #:exists 'replace)
(void))
(define (cached-require path-string key)

@ -19,6 +19,8 @@
(define mode-pagetree 'ptree)
(define mode-template 'template)
(define cache-filename "pollen.cache")
(define decodable-extensions (list markup-source-ext pagetree-source-ext))
(define default-pagetree "index.ptree")

Loading…
Cancel
Save