Function: eca-chat--completion-cached-items

eca-chat--completion-cached-items is a natively compiled function defined in eca-chat-context.el.

Signature

(eca-chat--completion-cached-items CACHE-VAR QUERY FETCH-FN KEY TO-ITEM-FN)

Documentation

Return completion items for QUERY, caching them in CACHE-VAR.

CACHE-VAR is a buffer-local hash table variable, created on demand. On cache miss call FETCH-FN; when it returns a response plist, convert each element of its KEY list with TO-ITEM-FN and cache the result. Interrupted requests (nil response) are not cached so they are retried on the next keystroke.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-chat-context.el
(defun eca-chat--completion-cached-items (cache-var query fetch-fn key to-item-fn)
  "Return completion items for QUERY, caching them in CACHE-VAR.
CACHE-VAR is a buffer-local hash table variable, created on
demand.  On cache miss call FETCH-FN; when it returns a response
plist, convert each element of its KEY list with TO-ITEM-FN and
cache the result.  Interrupted requests (nil response) are not
cached so they are retried on the next keystroke."
  (let* ((cache (or (symbol-value cache-var)
                    (set cache-var (make-hash-table :test 'equal))))
         (cached (gethash query cache :eca-chat--miss)))
    (if (not (eq cached :eca-chat--miss))
        cached
      (when-let ((resp (funcall fetch-fn)))
        (let ((items (-map to-item-fn (append (plist-get resp key) nil))))
          (when (> (hash-table-count cache) eca-chat--completion-cache-max-size)
            (clrhash cache))
          (puthash query items cache)
          items)))))