Skip to content

Commit

Permalink
support :never for resource-refresh-overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
jinnovation committed Apr 12, 2024
1 parent 44ceb82 commit ec84f18
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 6 deletions.
38 changes: 38 additions & 0 deletions docs/how-tos/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docs/references/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 14 additions & 6 deletions kele.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ec84f18

Please sign in to comment.