aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/emms.texinfo8
-rw-r--r--lisp/emms-browser.el24
2 files changed, 32 insertions, 0 deletions
diff --git a/doc/emms.texinfo b/doc/emms.texinfo
index dc6664d..0777e14 100644
--- a/doc/emms.texinfo
+++ b/doc/emms.texinfo
@@ -1677,6 +1677,14 @@ upon change in the source folder.
Customize @var{emms-browser-covers-file-extensions} to include or exclude
specific extensions.
+'emms-browser-cache-thumbnail' might be everytime a cover is queried, so
+to help with performance you can also set @var{emms-browser-covers} to
+'emms-browser-cache-thumbnail-async'. The latter is like the former
+except that it caches queries: every subsequent query will be much
+faster. The drawback is that it won't see changes made to covers after
+the first query. To force-refresh the thumbnail cache, you can run
+'emms-browser-clear-cache-hash'.
+
Also, Emacs by default will jump around a lot when scrolling a buffer
with images. In order to prevent that, you can set
@var{scroll-up-aggressively} and @var{scroll-down-aggressively} to the
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