Skip to content

Commit

Permalink
enhance(el): optimize cache by removing properties and word boundaries
Browse files Browse the repository at this point in the history
  • Loading branch information
roife committed Nov 14, 2023
1 parent c24763a commit e663036
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions emt.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
;;; Code:

(eval-when-compile (require 'thingatpt))
(eval-when-compile (require 'subr-x))

;;; Customize

Expand Down Expand Up @@ -85,6 +86,7 @@

(defun emt--cache-get (key)
"Get the value of KEY in cache."
(setq key (string-trim (substring-no-properties key) "\\W*" "\\W*"))
(let ((value (gethash key emt--cache-set)))
(when value
(setq emt--cache-lru-list (delete key emt--cache-lru-list))
Expand All @@ -93,6 +95,7 @@

(defun emt--cache-put (key value)
"Put KEY and VALUE into cache."
(setq key (string-trim (substring-no-properties key) "\\W*" "\\W*"))
(puthash key value emt--cache-set)
(push key emt--cache-lru-list)
(when (> (length emt--cache-lru-list) emt--cache-lru-size)
Expand Down

0 comments on commit e663036

Please sign in to comment.