RequestCache: started tracking timeAdded and timeToLive

This commit is contained in:
Art Lowel
2017-02-22 12:59:11 +01:00
parent bb5575cd27
commit 7fb8360f10
3 changed files with 10 additions and 6 deletions

View File

@@ -63,13 +63,15 @@ export class RequestCacheSuccessAction implements Action {
type = RequestCacheActionTypes.SUCCESS;
payload: {
key: string,
resourceUUIDs: Array<string>
resourceUUIDs: Array<string>,
msToLive: number
};
constructor(key: string, resourceUUIDs: Array<string>) {
constructor(key: string, resourceUUIDs: Array<string>, msToLive: number) {
this.payload = {
key,
resourceUUIDs
resourceUUIDs,
msToLive
};
}
}

View File

@@ -83,7 +83,9 @@ function success(state: RequestCacheState, action: RequestCacheSuccessAction): R
[action.payload.key]: Object.assign({}, state[action.payload.key], {
isLoading: false,
resourceUUIDs: action.payload.resourceUUIDs,
errorMessage: undefined
errorMessage: undefined,
timeAdded: new Date().getTime(),
msToLive: action.payload.msToLive
})
});
}

View File

@@ -40,7 +40,7 @@ export abstract class DataEffects<T extends CacheableObject> {
});
})
.map((ts: Array<T>) => ts.map(t => t.uuid))
.map((ids: Array<string>) => new RequestCacheSuccessAction(action.payload.key, ids))
.map((ids: Array<string>) => new RequestCacheSuccessAction(action.payload.key, ids, GlobalConfig.cache.msToLive))
.catch((errorMsg: string) => Observable.of(new RequestCacheErrorAction(action.payload.key, errorMsg)));
});
@@ -53,7 +53,7 @@ export abstract class DataEffects<T extends CacheableObject> {
.do((t: T) => {
this.objectCache.add(t, GlobalConfig.cache.msToLive);
})
.map((t: T) => new RequestCacheSuccessAction(action.payload.key, [t.uuid]))
.map((t: T) => new RequestCacheSuccessAction(action.payload.key, [t.uuid], GlobalConfig.cache.msToLive))
.catch((errorMsg: string) => Observable.of(new RequestCacheErrorAction(action.payload.key, errorMsg)));
});