switched to self links as keys in the object cache

This commit is contained in:
Art Lowel
2017-09-15 18:02:29 +02:00
parent f6ca6e6136
commit 0d4b064541
19 changed files with 236 additions and 231 deletions

View File

@@ -8,11 +8,11 @@ import { CacheEntry } from './cache-entry';
/**
* An interface to represent objects that can be cached
*
* A cacheable object should have a uuid
* A cacheable object should have a self link
*/
export interface CacheableObject {
uuid: string;
self?: string;
uuid?: string;
self: string;
}
/**
@@ -28,11 +28,11 @@ export class ObjectCacheEntry implements CacheEntry {
/**
* The ObjectCache State
*
* Consists of a map with UUIDs as keys,
* Consists of a map with self links as keys,
* and ObjectCacheEntries as values
*/
export interface ObjectCacheState {
[uuid: string]: ObjectCacheEntry
[href: string]: ObjectCacheEntry
}
// Object.create(null) ensures the object has no default js properties (e.g. `__proto__`)
@@ -81,7 +81,7 @@ export function objectCacheReducer(state = initialState, action: ObjectCacheActi
*/
function addToObjectCache(state: ObjectCacheState, action: AddToObjectCacheAction): ObjectCacheState {
return Object.assign({}, state, {
[action.payload.objectToCache.uuid]: {
[action.payload.objectToCache.self]: {
data: action.payload.objectToCache,
timeAdded: action.payload.timeAdded,
msToLive: action.payload.msToLive,