[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/osm 03d4ceb553 57/77: Add tile memory cache
From: |
ELPA Syncer |
Subject: |
[elpa] externals/osm 03d4ceb553 57/77: Add tile memory cache |
Date: |
Mon, 7 Mar 2022 08:58:08 -0500 (EST) |
branch: externals/osm
commit 03d4ceb553744a28db67b4ed3a7245a23b215f07
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Add tile memory cache
---
osm.el | 36 ++++++++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 4 deletions(-)
diff --git a/osm.el b/osm.el
index d12fed13e2..0dd3b9084c 100644
--- a/osm.el
+++ b/osm.el
@@ -124,6 +124,10 @@
Should be at least 7 days according to the server usage policies."
:type '(choice (const nil) integer))
+(defcustom osm-max-tiles 256
+ "Size of tile memory cache."
+ :type '(choice (const nil) integer))
+
(defvar osm-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "+" #'osm-zoom-in)
@@ -173,6 +177,12 @@ Should be at least 7 days according to the server usage
policies."
(defvar osm--clean-cache 0
"Last time the tile cache was cleaned.")
+(defvar osm--tiles nil
+ "Global tile memory cache.")
+
+(defvar osm--cookie 0
+ "Tile cache cookie.")
+
(defvar-local osm--url-index 0
"Current url index to query the servers in a round-robin fashion.")
@@ -481,10 +491,21 @@ Should be at least 7 days according to the server usage
policies."
(defun osm--get-tile (x y)
"Get tile at X/Y."
- (let ((file (osm--tile-file x y osm--zoom)))
- (when (file-exists-p file)
- `(image :type ,(if (member (file-name-extension file) '("jpg" "jpeg"))
'jpeg 'png)
- :width 256 :height 256 :file ,file))))
+ (let* ((key `(,osm-server ,osm--zoom ,x . ,y))
+ (tile (and osm--tiles (gethash key osm--tiles))))
+ (if tile
+ (progn (setcar tile osm--cookie) (cdr tile))
+ (let ((file (osm--tile-file x y osm--zoom)))
+ (when (file-exists-p file)
+ (when (and osm-max-tiles (not osm--tiles))
+ (setq osm--tiles (make-hash-table :test #'equal :size
osm-max-tiles)))
+ (setq tile
+ `(,osm--cookie
+ image :type ,(if (member (file-name-extension file) '("jpg"
"jpeg")) 'jpeg 'png)
+ :width 256 :height 256 :file ,file))
+ (when osm--tiles
+ (puthash key tile osm--tiles))
+ (cdr tile))))))
(defun osm--display-tile (x y tile)
"Display TILE at X/Y."
@@ -575,6 +596,13 @@ Should be at least 7 days according to the server usage
policies."
(tile (osm--get-tile x y)))
(osm--display-tile x y tile)
(unless tile (osm--enqueue x y))))))
+ (cl-incf osm--cookie)
+ (when (and osm--tiles (> (hash-table-count osm--tiles) osm-max-tiles))
+ (let (items)
+ (maphash (lambda (k v) (push (cons (car v) k) items)) osm--tiles)
+ (setq items (sort items #'car-less-than-car))
+ (dotimes (_ (- (hash-table-count osm--tiles) osm-max-tiles))
+ (remhash (cdr (pop items)) osm--tiles))))
(setq osm--queue
(sort osm--queue
(pcase-lambda (`(,x1 ,y1 . ,_z1) `(,x2 ,y2 . ,_z2))
- [elpa] externals/osm 28d3305bef 32/77: Improve handling of generated names, (continued)
- [elpa] externals/osm 28d3305bef 32/77: Improve handling of generated names, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 833793ed6c 77/77: Use grid placeholder, ELPA Syncer, 2022/03/07
- [elpa] externals/osm adc8156a70 37/77: README: Add more examples, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 7ac6f60b90 39/77: README update, ELPA Syncer, 2022/03/07
- [elpa] externals/osm ff5c089087 52/77: Update completion predicates, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d5c5dc6ffd 75/77: Mouse dragging: Check window, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 162f883f80 35/77: Reuse existing buffer, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 9053d8a930 16/77: Indentation, ELPA Syncer, 2022/03/07
- [elpa] externals/osm f2fba2ebdf 43/77: Auto rename the buffers, ELPA Syncer, 2022/03/07
- [elpa] externals/osm b991de6e89 54/77: Rename server, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 03d4ceb553 57/77: Add tile memory cache,
ELPA Syncer <=
- [elpa] externals/osm f6c16a4cc4 63/77: Improve keybindings, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 2a0bd8c7eb 50/77: Improve header line, ELPA Syncer, 2022/03/07
- [elpa] externals/osm e546671a0e 38/77: Minor cleanup, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 7657cb1b3b 71/77: Add check for image format support, ELPA Syncer, 2022/03/07
- [elpa] externals/osm e78a337477 44/77: Rename commands, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 1b7f4020b3 73/77: Fix caching, ELPA Syncer, 2022/03/07
- [elpa] externals/osm d27892f63a 40/77: Add some utility functions, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 3c0950a24b 31/77: Simplify bookmark handling, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 11a04bb5b9 66/77: osm-server: Improve completion command, ELPA Syncer, 2022/03/07
- [elpa] externals/osm 88e7e36e43 49/77: Rename function, ELPA Syncer, 2022/03/07