aboutsummaryrefslogtreecommitdiff
path: root/lisp/emms-browser.el
diff options
context:
space:
mode:
authorPierre Neidhardt <mail@ambrevar.xyz>2019-02-21 17:46:58 +0100
committerPierre Neidhardt <mail@ambrevar.xyz>2019-02-21 17:47:41 +0100
commit6013464eb7295fcd749b3146f758fc9295fbe11a (patch)
tree0fe27a6ced292385349b89e933fabe9d105ca70b /lisp/emms-browser.el
parent4eed4ce2f8105245617e5e529077c5a6635e45f8 (diff)
* lisp/emms-browser.el: Add emms-browser-cache-thumbnail-async for faster thumbnail lookups.
Diffstat (limited to 'lisp/emms-browser.el')
-rw-r--r--lisp/emms-browser.el24
1 files changed, 24 insertions, 0 deletions
diff --git a/lisp/emms-browser.el b/lisp/emms-browser.el
index b930d8b..f805b3b 100644
--- a/lisp/emms-browser.el
+++ b/lisp/emms-browser.el
@@ -2226,5 +2226,29 @@ will always use the same cover per folder.
(setq cache-dest-file nil))))
cache-dest-file)))))
+(defvar emms-browser--cache-hash nil
+ "Cache for `emms-browser-cache-thumbnail-async'.")
+
+(defun emms-browser-cache-thumbnail-async (dir size)
+ "Like `emms-browser-cache-thumbnail' but caches queries for faster lookups.
+The drawback is that if changes are made to the covers in DIR
+after `emms-browser-cache-thumbnail-async' queried them, it won't
+be taken into account. Call `emms-browser-clear-cache-hash' to
+refresh the cache."
+ (unless emms-browser--cache-hash
+ (setq emms-browser--cache-hash (make-hash-table :test 'equal)))
+ (let* ((key (cons dir size))
+ (val (gethash key emms-browser--cache-hash)))
+ (or val
+ (puthash key (emms-browser-cache-thumbnail dir size)
+ emms-browser--cache-hash))))
+
+(defun emms-browser-clear-cache-hash ()
+ "Resets `emms-browser-cache-thumbnail-async' cache.
+This is useful if there were changes on disk after
+`emms-browser-cache-thumbnail-async' first cached them."
+ (interactive)
+ (clrhash emms-browser--cache-hash))
+
(provide 'emms-browser)
;;; emms-browser.el ends here