From ec84f18fc7ca8a232921e70ab98cbc468c97b79a Mon Sep 17 00:00:00 2001 From: Jonathan Jin Date: Fri, 12 Apr 2024 12:52:11 -0400 Subject: [PATCH] support :never for resource-refresh-overrides --- docs/how-tos/customization.md | 38 +++++++++++++++++++++++++++++++++++ docs/references/changelog.md | 2 ++ kele.el | 20 ++++++++++++------ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/docs/how-tos/customization.md b/docs/how-tos/customization.md index ba52c0a2..889d0c8f 100644 --- a/docs/how-tos/customization.md +++ b/docs/how-tos/customization.md @@ -58,6 +58,44 @@ the `kele-get` result buffer's keybindings. Kele provides a handful of customization variables with which you can influence [cache behavior](../explanations/design.md#caches). +### Changing resource caching expiration time + +!!! note + + Currently only namespace names are cached. + +Kele caches certain resource names upon fetching. This speeds up subsequent +queries drastically. + +These cached values have a expiration time, after which the cached values are +erased. + +You can change the default refresh interval with +`kele-resource-default-refresh-interval`. For example, a value of `60` means +that all cached values are erased 60 seconds after creation. + +### Changing resource-specific caching expiration time + +For some resources, you might expect the set of names in the cluster to change +more or less frequently than others. Some you might, for all intents and +purposes, assume **never** change. + +You can set resource-specific cache expirations with +`kele-resource-refresh-overrides`. For example, the following will set cached +names for Pods to expire after 600 seconds: + +```emacs-lisp +(setq kele-resource-refresh-overrides '((pod . 600))) +``` + +You can **also** set the special value `:never`, in which case the cached values +are **never** automatically erased once they're written. For example, the +following will set cached names for Namespaces to never expire: + +```emacs-lisp +(setq kele-resource-refresh-overrides '((namespace . :never))) +``` + ### Change the discovery cache polling interval If you'd like Kele to poll the discovery cache more or less frequently than the default, set diff --git a/docs/references/changelog.md b/docs/references/changelog.md index f3262eb4..694221f3 100644 --- a/docs/references/changelog.md +++ b/docs/references/changelog.md @@ -17,6 +17,8 @@ versioning][semver]. **Kubernetes** section on the menu bar - Added ability to switch contexts from within the menu bar; available contexts are shown as a sub-menu +- Added ability to specify that cached names of a specific resource should never + expire ### Fixed diff --git a/kele.el b/kele.el index ba1c52ba..0f3de10a 100644 --- a/kele.el +++ b/kele.el @@ -82,9 +82,14 @@ If a resource is listed here, the corresponding value will be used for cache time-to-live for that resource. Otherwise, `kele-resource-default-refresh-interval' is used. +If the value is :never, then the resource will be cached once and +then never expired. + Keys are the singular form of the resource name, e.g. \"pod\" for pods." - :type '(alist :key-type symbol :value-type 'integer) + :type '(alist :key-type symbol :value-type (radio + (integer :tag "Expiration duration in seconds") + (const :tag "Never expire once cached" :never))) :group 'kele) (defcustom kele-discovery-refresh-interval @@ -821,11 +826,14 @@ The cache has a TTL as defined by Returns the passed-in list of namespaces." (add-to-list 'kele--namespaces-cache `(,(intern context) . ,namespace-names)) - (run-with-timer - (kele--get-cache-ttl-for-resource 'namespace) - nil - #'kele--clear-namespaces-for-context - context) + (let ((ttl (kele--get-cache-ttl-for-resource 'namespace))) + ;; TODO: Test :never + (when (and ttl (not (eq ttl :never))) + (run-with-timer + (kele--get-cache-ttl-for-resource 'namespace) + nil + #'kele--clear-namespaces-for-context + context))) namespace-names) (cl-defstruct (kele--resource-container