angelnikolov / ts-cacheable

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

How to override default values from custom config settings? #9

Closed mendezgabriel closed 6 years ago

mendezgabriel commented 6 years ago

Hi,

This is not an issue but more of a query since I'd like to pass some values to the Cacheable decorator dynamically. These would be defined in a config file and converted into an object. Essentially I have a service which contains several methods I'd like to cache like this: ... @Cacheable({ maxAge: this.config.cacheExpirationTimeInMilliseconds }) getCountries() { return this.http.get("api/Countries"); } ... I'm struggling to do that, since I always get an undefined reference on the config object. What should be the proper way to do this? Or better yet, how can I override default values being used by the decorator and what are those values?

Thanks in advance.

ThibaudAV commented 6 years ago

Why don't you use Angular environment variables ?

mendezgabriel commented 6 years ago

It's a legacy app and I am making some performance improvements, not too much room for refactoring. Would you give me an example of how it would work with environment variables? BTW the project is using webpack for building, not Angular CLI :(

ThibaudAV commented 6 years ago

Here is an example : https://alligator.io/angular/environment-variables/ but it uses Angular CLI.

Maybe this can help : https://stackoverflow.com/questions/42252990/angular-2-webpack-environment-configurations

mendezgabriel commented 6 years ago

Thanks! The second article gave me some ideas 👍