tldr-pages / tldr-node-client

Node.js command-line client for tldr pages
https://www.npmjs.com/package/tldr
MIT License
431 stars 71 forks source link

specify a config param to control updating cache when a page is not found #225

Open gpenghe opened 6 years ago

gpenghe commented 6 years ago

Expected behaviour

Actual behaviour

Currently tldr tried to update the cache every time it doesn't recognize a command. It's a bit slow process that involves a network communication. And also it seems it's at least not necessary to do it every time, which is the case when the user tries to see if the command becomes recognized after a cache update, or when the user just check several commands in a row. The latter case happens a lot to a user without auto-completion installed.

Log, debug output

$ tldr sss
✔ Page not found. Updating cache
✔ Creating index
Page not found.
Feel free to send a pull request to: https://github.com/tldr-pages/tldr
$ tldr sss
✔ Page not found. Updating cache
✔ Creating index
Page not found.
Feel free to send a pull request to: https://github.com/tldr-pages/tldr

Environment

sbrl commented 6 years ago

Hey, thanks for the issue! I suspect this behaviour should be configured via a setting (which ought to default to on). @agnivade, thoughts?

agnivade commented 6 years ago

Agree. We already have a cache.lastUpdated() function. So we just need a new config value which specifies the duration. And then when a page is not found, we just check whether now() - cache.lastUpdated() is greater than the duration, if yes, then update the cache.

I am available for reviews if anyone wants to send a PR.