emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/osm 01dc16ac90 9/9: Add osm-max-cache


From: ELPA Syncer
Subject: [elpa] externals/osm 01dc16ac90 9/9: Add osm-max-cache
Date: Fri, 22 Dec 2023 12:58:28 -0500 (EST)

branch: externals/osm
commit 01dc16ac90d2e4f44d6e5843eb7f738332e5e329
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Add osm-max-cache
---
 CHANGELOG.org |  1 +
 osm.el        | 17 +++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 2fc37479ed..d2a9c84e61 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -14,6 +14,7 @@
 - Unify ~osm-bookmark-set~ and ~osm-bookmark-set-click~.
 - Add distance measurement for manual track. Press ~S-<mouse-1>~ 
(~osm-mouse-track~)
   to place the pins of the track.
+- Add ~osm-max-cache~ to keep image cache size in check.
 
 * Version 1.0 (2023-12-01)
 
diff --git a/osm.el b/osm.el
index b8f3f0eab3..b4912d498d 100644
--- a/osm.el
+++ b/osm.el
@@ -226,7 +226,11 @@ Should be at least 7 days according to the server usage 
policies."
   :type '(choice (const nil) natnum))
 
 (defcustom osm-max-tiles 256
-  "Size of tile memory cache."
+  "Number of tiles to keep in the memory cache."
+  :type '(choice (const nil) natnum))
+
+(defcustom osm-max-cache 64
+  "Image cache size in megabytes."
   :type '(choice (const nil) natnum))
 
 (defun osm--menu-item (menu &optional name)
@@ -1101,7 +1105,6 @@ xmlns='http://www.w3.org/2000/svg' 
xmlns:xlink='http://www.w3.org/1999/xlink'>
 
 (defun osm--revert (&rest _)
   "Revert osm buffers."
-  (clear-image-cache t)
   (setq osm--tile-cache nil)
   (dolist (buf (buffer-list))
     (when (eq (buffer-local-value 'major-mode buf) #'osm-mode)
@@ -1158,14 +1161,14 @@ xmlns='http://www.w3.org/2000/svg' 
xmlns:xlink='http://www.w3.org/1999/xlink'>
 (defun osm--update ()
   "Update map display."
   (osm--barf-unless-osm)
+  (osm--purge-tile-cache)
+  (osm--purge-directory)
   (osm--rename-buffer)
   (osm--update-sizes)
   (osm--update-header)
   (osm--update-buffer)
   (osm--update-copyright)
-  (osm--process-download-queue)
-  (osm--purge-tile-cache)
-  (osm--purge-directory))
+  (osm--process-download-queue))
 
 (defun osm--update-sizes ()
   "Update window sizes."
@@ -1257,7 +1260,9 @@ xmlns='http://www.w3.org/2000/svg' 
xmlns:xlink='http://www.w3.org/1999/xlink'>
       (maphash (lambda (k v) (push (cons (car v) k) items)) osm--tile-cache)
       (setq items (sort items #'car-less-than-car))
       (dotimes (_ (- (hash-table-count osm--tile-cache) osm-max-tiles))
-        (remhash (cdr (pop items)) osm--tile-cache)))))
+        (remhash (cdr (pop items)) osm--tile-cache))))
+  (when (and osm-max-cache (> (image-cache-size) (* 1024 1024 osm-max-cache)))
+    (clear-image-cache t)))
 
 (defun osm--bookmark-record-default ()
   "Make osm bookmark record."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]