Function: marginalia--cached

marginalia--cached is a byte-compiled function defined in marginalia.el.

Signature

(marginalia--cached CACHE FUN KEY)

Documentation

Cached application of function FUN with KEY.

The CACHE keeps around the last marginalia--cache-size computed annotations. The cache is mainly useful when scrolling in completion UIs like Vertico or Icomplete.

Source Code

;; Defined in ~/.emacs.d/elpa/marginalia-20260724.810/marginalia.el
(defun marginalia--cached (cache fun key)
  "Cached application of function FUN with KEY.
The CACHE keeps around the last `marginalia--cache-size' computed
annotations.  The cache is mainly useful when scrolling in
completion UIs like Vertico or Icomplete."
  (if cache
      (let ((ht (cdr cache)))
        (or (gethash key ht)
            (let ((val (funcall fun key)))
              (push key (car cache))
              (puthash key val ht)
              (when (>= (hash-table-count ht) marginalia--cache-size)
                (let ((end (last (car cache) 2)))
                  (remhash (cadr end) ht)
                  (setcdr end nil)))
              val)))
    (funcall fun key)))