Skip to content

Commit

Permalink
allow no-caching for --get-namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnovation committed Apr 12, 2024
1 parent 97cdd1c commit 4580bcf
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -793,14 +793,19 @@ If value is nil, the namespaces need to be fetched directly.")
(setq kele--namespaces-cache
(assoc-delete-all (intern context) kele--namespaces-cache)))

(defun kele--get-namespaces (context)
;; TODO: test :cache nil
(cl-defun kele--get-namespaces (context &key (cache t))
"Get namespaces for CONTEXT.
If not cached, will fetch and cache the namespaces."
(if-let ((namespaces (alist-get (intern context) kele--namespaces-cache)))
namespaces
(apply #'kele--cache-namespaces context
(kele--fetch-resource-names nil "v1" "namespaces" :context context))))
If the namespaces are cached, return the cached value.
If CACHE is non-nil, cache the fetched namespaces."
(if-let ((cached-namespaces (alist-get (intern context) kele--namespaces-cache)))
cached-namespaces
(let ((namespaces (kele--fetch-resource-names nil "v1" "namespaces" :context context)))
(if cache
(apply #'kele--cache-namespaces context namespaces)
namespaces))))

(defun kele--get-cache-ttl-for-resource (resource)
"Get the cache TTL for RESOURCE."
Expand All @@ -815,7 +820,7 @@ The cache has a TTL as defined by
`kele-resource-default-refresh-interval'.
Returns the passed-in list of namespaces."
(add-to-list 'kele--namespaces-cache `(,(intern context) . ,namespace-names))
(add-to-list 'kele--context-namespaces `(,(intern context) . ,namespace-names))
(run-with-timer
(kele--get-cache-ttl-for-resource 'namespace)
nil
Expand Down

0 comments on commit 4580bcf

Please sign in to comment.