I would like to use ReactiveJS Observable
method for the below use case.
IF MAIN_CACHE EXIST
RETURN OUTPUT
ELSE IF DB CONNECTION EXIST
CACHE MAIN_CACHE (1 Hour)
CACHE FALLBACK_CACHE (3 Days)
RETURN OUTPUT
ELSE IF FALLBACK_CACHE EXIST
RETURN OUTPUT
I got the expected output but i feel this leads to Callback Hell
and I think, still its not a good approach and i'm missing something in ReactiveJS Observable
key benefits.
Below is my code and the whole code is in JS Bin Link
mainCache.subscribe(function (response) {
console.log(response);
}, function (error) {
dbData.subscribe(function (response) {
console.log(response);
}, function (error) {
console.log('DB CAL Log info', error);
fallbackCache.subscribe(function (response) {
console.log('FALLBACK CACHE SERVED');
console.log(response);
}, function (error) {
console.log('DB CAL Log error', error);
});
});
});
Any lights. much appreciated with working example.