angelnikolov / ts-cacheable

Observable/Promise Cache Decorator
https://npmjs.com/package/ts-cacheable
ISC License
340 stars 42 forks source link

Question about memory #11

Closed ArielGueta closed 6 years ago

ArielGueta commented 6 years ago

Thanks for this great library, very useful. I'm wondering how do u know that it does not create a memory leak in your application? I mean when the cache is garbage collected?

angelnikolov commented 6 years ago

It wouldn't create a memory leak, because the caching resolver should always be deterministic. I.e if you have cached a method invoked with a parameter test and then go to a different page, the cached results will still be there. When you go back to a page which invokes the same method, with the same parameter, you will access the cache version. Holding a reference to something that you "might" want in future is not a memory leak. A memory leak would be if you have a reference to the test payload, but when calling the same method again, you create a new value, refer to it again, and all that - without dereferencing the old payload, which will essentially cause infinite memory build up. I've profiled the decorator in a pretty large application and it didn't seem to build up in memory, but if it does for you, let me know. Thanks! @ArielGueta

ArielGueta commented 6 years ago

Thanks!