-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add maxAge
option for alfy.cache
- fixes #3
#4
Conversation
The downside of this approach is that it isn't possible to implement a fallback mechanism like I do in alfred-ng2. If the cache is expired, it tries to load the remote data, if that fails it will still load the "old" cache. It would be nice if it was possible to still support that. It actually is possible if you use alfy.cache.set('foo', 'bar', {maxAge: 5000});
await delay(5000);
alfy.cache.get('foo');
//=> undefined
alfy.cache.get('foo', true);
//=> 'bar' |
Hmm, maybe we should bundle |
maxAge
option for alfy.cache
- resolves #3maxAge
option for alfy.cache
- fixes #3
Not sure if we should bundle alfy.got.get('https://myapi.com/foo/bar.json', {maxAge: 5000}).then(res => {
console.log(res.body);
// {foo: 'bar'}
}); |
@SamVerschueren Fetching from network is a very common operation in Alfred workflows. Would be nice to simplify it. Dependencies are super cheap anyways as they're bundled with the workflow, not I'm thinking: alfy.fetch('https://myapi.com/foo/bar.json', {maxAge: 5000}).then(res => {
console.log(res.body);
// {foo: 'bar'}
}); And maybe even make To be clear, this is in addition what's currently in this PR, not instead of. Should probably be a separate PR. |
So we would only expose the
👍
Will add it after this one gets merged. Is it ok to remove the cached data then when it is expired? Or should we just ignore it without removing it? |
Yup.
Then they can just pass the
For |
👍
👍 |
|
||
```js | ||
alfy.cache.set('foo', 'bar', {maxAge: 5000}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do a alfy.cache.get('foo');
and show the value before the delay too. For clarity.
Example: | ||
|
||
```js | ||
const delay = require('delay'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer a require at the top instead of await require('delay')(5000)
. But if you want it inline, I'll fix it :).
Looks superb, as always :) |
Awesome. Super nice to see this land :)! If #6 is implemented, I nearly don't have to do anything anymore in my |
Conf
class and override theset
,get
andhas
methodsmaxAge
optionAs described in #3, not sure if we should do it with the
CacheConf
object here, add that option toConf
or create an externalCacheConf
module to handle this. Will to do either one of those :).Feel free to suggest improvements of the code or docs.