diff options
Diffstat (limited to 'emms-info.el')
-rw-r--r-- | emms-info.el | 88 |
1 files changed, 12 insertions, 76 deletions
diff --git a/emms-info.el b/emms-info.el index c4533bd..0edeb85 100644 --- a/emms-info.el +++ b/emms-info.el @@ -67,33 +67,6 @@ Each is called with a track as argument." (defvar emms-info-asynchronous-tracks 0 "Number of tracks we're waiting for to be done.") -;; cache support (break into a separate file and make -;; emms-info-really-initialize-track into a variable controlling which -;; function to use)? - -;; The cache is invalidated when track names are changed. It also does -;; not differenciate between file or uri tracks, and relies on the -;; uniqueness of the name. - -;; usage - in your .emacs - -;; (add-hook 'after-init-hook 'emms-info-cache-restore) -;; (add-hook 'kill-emacs-hook 'emms-info-cache-save) - -;; this is works much better with a later-do-interval of something -;; like 0.001 - -(define-hash-table-test 'string-hash 'string= 'sxhash) -(defvar emms-info-cache (make-hash-table :test 'string-hash) - "A mapping of paths to file info. -This is used to cache file info over emacs sessions.") - -(defvar emms-info-cache-file "~/.emms-cache" - "A file used to store cached file info information over sessions") - -(defvar emms-info-cache-dirty nil - "True if the cache has been updated since init.") - (defun emms-info-initialize-track (track) "Initialize TRACK with emms-info information. This is a suitable value for `emms-track-initialize-functions'." @@ -107,34 +80,18 @@ This is a suitable value for `emms-track-initialize-functions'." Return t when the track got changed." (let ((file-mtime (when emms-info-auto-update (emms-info-track-file-mtime track))) - (name (emms-track-get track 'name)) - cached-track - updated) - - (when (setq cached-track (gethash name emms-info-cache)) - ;; We need to modify TRACK. This way we lose information already - ;; present in TRACK, which is not necessarily what we want, but - ;; it's efficient. - (setcar track (car cached-track)) - (setcdr track (cdr cached-track))) - - ;; if uncached, or cached and the time has changed - (when (or (not cached-track) - (and cached-track - emms-info-auto-update - (let ((info-mtime (emms-track-get track 'info-mtime))) - (or (not (consp info-mtime)) - (emms-time-less-p info-mtime file-mtime))))) - (setq updated t) - (run-hook-with-args 'emms-info-functions track)) - - (emms-track-set track 'info-mtime file-mtime) - (emms-track-updated track) - - (when (or (not cached-track) - updated) - (puthash name track emms-info-cache) - (setq emms-info-cache-dirty t)) + (info-mtime (emms-track-get track 'info-mtime)) + (name (emms-track-get track 'name))) + + ;; if the file's been modified or is new + (when (or (not info-mtime) + (emms-time-less-p + info-mtime file-mtime)) + (run-hook-with-args 'emms-info-functions track) + ;; not set by info functions + (emms-track-set track 'info-mtime file-mtime) + (funcall emms-cache-set-function name track) + (emms-track-updated track)) (when emms-info-asynchronously (setq emms-info-asynchronous-tracks (1- emms-info-asynchronous-tracks)) @@ -142,27 +99,6 @@ Return t when the track got changed." (message "EMMS: All track information loaded."))) t)) -(defun emms-info-cache-save () - "Save the info cache to a file." - (when emms-info-cache-dirty - (message "Saving emms info cache...") - (set-buffer (get-buffer-create " emms-info-cache ")) - (erase-buffer) - (maphash (lambda (k v) - (insert (format - "(puthash %S '%S emms-info-cache)\n" k v))) - emms-info-cache) - (set-buffer-file-coding-system 'mule-utf-8) - (write-region (point-min) (point-max) emms-info-cache-file) - (kill-buffer (current-buffer)) - (message "Saving emms info cache...done") - (setq emms-info-cache-dirty nil))) - -(defun emms-info-cache-restore () - "Restore the info cache from a file." - (load emms-info-cache-file t nil t) - (setq emms-info-cache-dirty nil)) - (defun emms-info-track-file-mtime (track) "Return the mtime of the file of TRACK, if any. Return zero otherwise." |