Skip to content
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

changing contents of cached observable #12

Closed
jmls opened this issue Sep 26, 2018 · 6 comments
Closed

changing contents of cached observable #12

jmls opened this issue Sep 26, 2018 · 6 comments

Comments

@jmls
Copy link

jmls commented Sep 26, 2018

is it possible to change / emit new values from a cached call ?

Let's say I've loaded 40 items from an http call - and these are being displayed onscreen. Another session adds a new item - which notifies via websockets all interested clients.

How can I take this new item and insert it into the cache so my screen is updated withe the new record, without having to re-read the data from the http call ?

@angelnikolov
Copy link
Owner

angelnikolov commented Sep 27, 2018

Yes, you can use

@Cacheable({
    maxCacheCount: 40
})

. Let me know if that works for ya!

@jmls
Copy link
Author

jmls commented Sep 27, 2018

the 40 items are an array from a api call. I now have a new item that I want to insert into this array.

@angelnikolov
Copy link
Owner

angelnikolov commented Sep 27, 2018

Well can you do it @ the component level. Say you have

this.data = this.service.getCachedData() // this returns the initial forty items
socket.on('event', data=> this.data.push(data))

?
If you want to update the cache to contain 41 items afterwards, I don't think this is possible right now, since the cache is not exposed out of the decorator and it's accessed by it via closure.

@jmls
Copy link
Author

jmls commented Sep 27, 2018

yeah, I was trying to keep it at the store level - I thought that this may be the case. At the component level won't work because the next component that makes the same api request will get the old 40 items, unless I bust the cache and re-read (Which seems a shame as I have to re-read 41 items, where I already have the 40 in memory)

Thanks

@angelnikolov
Copy link
Owner

Yeah I remember that I was thinking about a third decorator called @CacheUpdater, which will basically work the same way as the @CacheBuster (i.e share a notifier subject) but only work one-way and be used to update the cache of the @Cacheable but didn't have time for it. If you got time and want to do it, go ahead, I think it will be a nice addition! :))

@angelnikolov
Copy link
Owner

Closing due to inactivity.

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

No branches or pull requests

2 participants