Add nu-complete cache helper by steinuil · Pull Request #931 · nushell/nu_scripts · GitHub
Skip to content

Add nu-complete cache helper#931

Draft
steinuil wants to merge 1 commit into
nushell:mainfrom
steinuil:nu-complete-cache
Draft

Add nu-complete cache helper#931
steinuil wants to merge 1 commit into
nushell:mainfrom
steinuil:nu-complete-cache

Conversation

@steinuil

Copy link
Copy Markdown

I wanted to propose a solution to issues with very slow command completions (as mentioned in nushell/nushell#11733 and #588) with a command that caches closure outputs in a SQLite db with an explicit expiration.

Usage

This can be used in custom completion functions to temporarily cache the output.

def "nu-complete kubectl services" [] {
  nu-complete cache --expire 1min {
     ^kubectl get services -o name | parse "service/{value}"
  }
}

Open points

  • Does it make sense to use the in-memory store for this? Since this is supposed to speed up slow commands, maybe the performance hit of just querying a disk DB would be negligible in comparison, and I would expect the DB to grow a lot in size after a while.
  • How and when do we clean up this DB?
  • Does it make sense to use view source on the closure as a key into this cache?
  • Can we check if the closure takes any arguments and throw an error?
  • Should the location of this DB be configurable? For now I just dropped it into XDG_CACHE_HOME, but not every system has that env variable available.

This is very much a WIP, if you have any suggestions please mention it!

@fdncred

fdncred commented Aug 14, 2024

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants