angelnikolov / ts-cacheable

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

turn off globally #60

Closed randallmeeker closed 4 years ago

randallmeeker commented 4 years ago

I'm doing server rendering and I'm trying to figure out the best way to turn this off when its run on the server.

Or basically turn it on / off based on some global setting.

angelnikolov commented 4 years ago

Hmm, there a couple of options to do this I guess.

  1. Do what Angular does and strip all decorators during compile time.
  2. Create a custom Storage strategy which wraps around the InMemoryStorageStrategy (if you use that on the client of course) but also has a flag based on which uses the caching strategy or not.
  3. Use some build plugin which re-routes all Cacheable imports to a dummy nooo function.
randallmeeker commented 4 years ago

thanks will have a look. while I'm asking is there a simple way to by pass the cache with an argument. I'm checking out items in the ICacheConfig but nothing appears to work. shouldCacheDecider appears to be after the fact that not before.

will close this as answered though.

angelnikolov commented 4 years ago

This is something we discussed before, but for now you can do it by using a helper method. Say you want to have getUsers cached, you can create a getUsersCached method which is decorated, and will always return the cached values. If you want to bypass cache, you call getUsers instead. Does that answer your question?

randallmeeker commented 4 years ago

yes, it is what I ended up doing for now. thanks