Cache asset metadata.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
diff --git a/asset.lisp b/asset.lisp
index 32a62b0..1f3a45e 100644
--- a/asset.lisp
+++ b/asset.lisp
@@ -32,7 +32,10 @@
:type extension)
(sources :initarg :sources
:reader asset-sources
- :type list)))
+ :type list)
+ (path :type string)
+ (source-path :type string)
+ (url :type string)))
(defgeneric asset-ext (asset))
(defgeneric asset-url (asset))
@@ -52,18 +55,26 @@
(mime-type (asset-ext asset)))
(defmethod asset-url ((asset asset))
- (expand-uri nil *assets-url-template*
- :name (asset-name asset)
- :ext (subseq (string-downcase (asset-ext asset)) 1)))
+ (if (slot-boundp asset 'url)
+ #1=(slot-value asset 'url)
+ (setf #1# (expand-uri nil *assets-url-template*
+ :name (asset-name asset)
+ :ext (subseq (string-downcase (asset-ext asset))
+ 1)))))
(defmethod asset-path ((asset asset))
- (expand-uri nil *assets-path-template*
- :name (asset-name asset)
- :ext (subseq (string-downcase (asset-ext asset)) 1)))
+ (if (slot-boundp asset 'path)
+ #1=(slot-value asset 'path)
+ (setf #1# (expand-uri nil *assets-path-template*
+ :name (asset-name asset)
+ :ext (subseq (string-downcase (asset-ext asset))
+ 1)))))
(defmethod asset-source-path ((asset asset))
- (with-slots (name source-dir source-ext) asset
- (str source-dir name source-ext)))
+ (if (slot-boundp asset 'source-path)
+ #1=(slot-value asset 'source-path)
+ (setf #1# (with-slots (name source-dir source-ext) asset
+ (str source-dir name source-ext)))))
(defmethod print-object ((asset asset) stream)
(print-unreadable-object (asset stream :type t)
diff --git a/find.lisp b/find.lisp
index 838633d..bd27adf 100644
--- a/find.lisp
+++ b/find.lisp
@@ -140,8 +140,19 @@
specs
:initial-value assets))
+;; Asset cache
+
+(defvar *asset-cache* (make-hash-table :test 'equal))
+
+(defun clear-asset-cache ()
+ (clrhash *asset-cache*))
+
+(defmacro asset-cache-get (key)
+ `(gethash ,key *asset-cache*))
+
(defun find-asset (spec &optional class)
- (first (find-assets-from-spec spec class)))
+ (or #1=(asset-cache-get `(find-asset ,spec ,class))
+ (setf #1# (first (find-assets-from-spec spec class)))))
;; Now that we can find an asset from a string spec we can also
;; add some sugar coating to asset methods.
diff --git a/package.lisp b/package.lisp
index aee5eca..9d30f46 100644
--- a/package.lisp
+++ b/package.lisp
@@ -61,6 +61,8 @@
#:find-assets-from-spec
#:find-assets-from-specs
#:locate-precompiled-assets
+ ;; Cache
+ #:clear-asset-cache
;; Rendering
#:quote-html
#:process-asset