type-cacheable
type-cacheable copied to clipboard
[Bug/Question] setClient throws error when setting it null & options.ttlSeconds not set
Hello !
Not sure if it's a bug or if we don't use this package correctly We're using this package (10.1.0) with @redis/client
When our redis loose it's connection, we want to disable the cache, until redis reconnect. To do so, we call the CacheManager with .setClient(null)
As client is null, and we don't specify the ttlSeconds, this.client.getClientTTL() throws an error
setClient(client) {
this.client = client;
if (this.options && !this.options.ttlSeconds) {
this.options.ttlSeconds = this.client.getClientTTL();
}
}
Are we missing something ? is there an other way to disable the cache temporarily ?
As a workaround, we just catch the call to setClient(null), and do nothing with this
I can propose a PR and add an condition on this.client in the if.
from:
if (this.options && !this.options.ttlSeconds) {
to:
if (this.client && this.options && !this.options.ttlSeconds) {