cache implemented. Need to add to the packager now.
This commit is contained in:
parent
59f58f9421
commit
9d3e72ae0a
|
@ -18,14 +18,19 @@
|
||||||
(make-directory* cache-directory-path)))
|
(make-directory* cache-directory-path)))
|
||||||
|
|
||||||
|
|
||||||
(define (ensure-cache-db-structure!)
|
;; clear-cache-files!: -> void
|
||||||
(when (not (file-exists? whalesong-cache.sqlite3))
|
;; Remove all the cache files.
|
||||||
;; Clear existing cache files: they're obsolete.
|
(define (clear-cache-files!)
|
||||||
(for ([file (directory-list cache-directory-path)])
|
(for ([file (directory-list cache-directory-path)])
|
||||||
(when (file-exists? (build-path cache-directory-path file))
|
(when (file-exists? (build-path cache-directory-path file))
|
||||||
(with-handlers ([exn:fail? void])
|
(with-handlers ([exn:fail? void])
|
||||||
(delete-file (build-path cache-directory-path file)))))
|
(delete-file (build-path cache-directory-path file))))))
|
||||||
|
|
||||||
|
|
||||||
|
(define (ensure-cache-db-structure!)
|
||||||
|
(when (not (file-exists? whalesong-cache.sqlite3))
|
||||||
|
;; Clear existing cache files: they're obsolete.
|
||||||
|
(clear-cache-files!)
|
||||||
(define conn
|
(define conn
|
||||||
(sqlite3-connect #:database whalesong-cache.sqlite3
|
(sqlite3-connect #:database whalesong-cache.sqlite3
|
||||||
#:mode 'create))
|
#:mode 'create))
|
||||||
|
@ -57,11 +62,17 @@
|
||||||
(prepare conn (string-append "select path, md5sum, data "
|
(prepare conn (string-append "select path, md5sum, data "
|
||||||
"from cache "
|
"from cache "
|
||||||
"where path=? and md5sum=?")))
|
"where path=? and md5sum=?")))
|
||||||
|
(define delete-cache-stmt
|
||||||
|
(prepare conn (string-append "delete from cache "
|
||||||
|
"where path=?")))
|
||||||
(define insert-cache-stmt
|
(define insert-cache-stmt
|
||||||
(prepare conn (string-append "insert into cache(path, md5sum, data)"
|
(prepare conn (string-append "insert into cache(path, md5sum, data)"
|
||||||
" values (?, ?, ?);")))
|
" values (?, ?, ?);")))
|
||||||
|
|
||||||
;; cached?:
|
|
||||||
|
;; cached?: path -> (U false (vector string bytes (U string bytes)))
|
||||||
|
;; Returns a true value, (vector path md5-signature data), if we can
|
||||||
|
;; find an appropriate entry in the cache, and false otherwise.
|
||||||
(define (cached? path)
|
(define (cached? path)
|
||||||
(cond
|
(cond
|
||||||
[(file-exists? path)
|
[(file-exists? path)
|
||||||
|
@ -74,15 +85,18 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; save-in-cache!: path string -> void
|
;; save-in-cache!: path (U string bytes) -> void
|
||||||
;; Saves a record.
|
;; Saves a record.
|
||||||
(define (save-in-cache! path data)
|
(define (save-in-cache! path data)
|
||||||
(cond
|
(cond
|
||||||
[(file-exists? path)
|
[(file-exists? path)
|
||||||
(query-exec conn
|
(define signature (call-with-input-file* path md5))
|
||||||
insert-cache-stmt
|
;; Make sure there's a unique row/column by deleting
|
||||||
|
;; any row with the same key.
|
||||||
|
(query-exec conn delete-cache-stmt (path->string path))
|
||||||
|
(query-exec conn insert-cache-stmt
|
||||||
(path->string path)
|
(path->string path)
|
||||||
(call-with-input-file* path md5)
|
signature
|
||||||
data)]
|
data)]
|
||||||
[else
|
[else
|
||||||
(error 'save-in-cache! "File ~e does not exist" path)]))
|
(error 'save-in-cache! "File ~e does not exist" path)]))
|
Loading…
Reference in New Issue
Block a user