-
Notifications
You must be signed in to change notification settings - Fork 16
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
Provide hook to notify on cache hit #8
Comments
With a callback, maybe something like getList.operation = 'READ';
getList.onCacheHit = function(res) {
console.log('hey')
});
function getList(query) {
const url = `${BASE_URL}search?query=${query}&hitsPerPage=200`;
return fetch(url)
.then(response => response.json())
.then(result => result.hits);
}
api.hackernews.getList().then(hits => this.list = hits); |
Or maybe providing a key on the api method itself With a callback, maybe something like getList.operation = 'READ';
function getList(query) {
const url = `${BASE_URL}search?query=${query}&hitsPerPage=200`;
return fetch(url)
.then(response => response.json())
.then((result) => {
console.log(getList.__cacheHit__) // boolean
return result.hits
});
} |
Speaking of callbacks - @petercrona and I are also discussing providing a hook to get notified when a cache entry is written/updated. In general from a philosophical standpoint we want to keep Ladda as simple as possible, so that you do not have a whole lot of buy in. Hooks typically mean that you couple your implementation with Ladda. Ideally your dependency to Ladda is so weak, that you could just remove it and your application would still work (just minus caching benefits) What is your use case to be notified on a cache hit? |
Feature request: Add some way to tell when a request has a cache hit (and/or miss).
Not sure if best as callback function, or providing the info as metadata by mutating the response as promise resolves, or via args
The text was updated successfully, but these errors were encountered: