mirror of
https://github.com/nasa/openmct.git
synced 2025-06-12 20:28:14 +00:00
disable cache
This commit is contained in:
@ -38,75 +38,25 @@ define(
|
|||||||
this.modelService = modelService;
|
this.modelService = modelService;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast-resolving promise
|
|
||||||
function fastPromise(value) {
|
|
||||||
return (value || {}).then ? value : {
|
|
||||||
then: function (callback) {
|
|
||||||
return fastPromise(callback(value));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
CachingModelDecorator.prototype.getModels = function (ids) {
|
CachingModelDecorator.prototype.getModels = function (ids) {
|
||||||
var cacheService = this.cacheService,
|
var loadFromCache = ids.filter(function cached(id) {
|
||||||
neededIds = ids.filter(function notCached(id) {
|
return this.cacheService.has(id);
|
||||||
return !cacheService.has(id);
|
}, this),
|
||||||
});
|
loadFromService = ids.filter(function notCached(id) {
|
||||||
|
return !this.cacheService.has(id);
|
||||||
|
}, this);
|
||||||
|
|
||||||
// Update the cached instance of a model to a new value.
|
if (!loadFromCache.length) {
|
||||||
// We update in-place to ensure there is only ever one instance
|
return this.modelService.getModels(loadFromService);
|
||||||
// of any given model exposed by the modelService as a whole.
|
|
||||||
function updateModel(id, model) {
|
|
||||||
var oldModel = cacheService.get(id);
|
|
||||||
|
|
||||||
// Same object instance is a possibility, so don't copy
|
|
||||||
if (oldModel === model) {
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we'd previously cached an undefined value, or are now
|
|
||||||
// seeing undefined, replace the item in the cache entirely.
|
|
||||||
if (oldModel === undefined || model === undefined) {
|
|
||||||
cacheService.put(id, model);
|
|
||||||
return model;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, empty out the old model...
|
|
||||||
Object.keys(oldModel).forEach(function (k) {
|
|
||||||
delete oldModel[k];
|
|
||||||
});
|
|
||||||
|
|
||||||
// ...and replace it with the contents of the new model.
|
|
||||||
Object.keys(model).forEach(function (k) {
|
|
||||||
oldModel[k] = model[k];
|
|
||||||
});
|
|
||||||
|
|
||||||
return oldModel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store the provided models in our cache
|
return this.modelService.getModels(loadFromService)
|
||||||
function cacheAll(models) {
|
.then(function (modelResults) {
|
||||||
Object.keys(models).forEach(function (id) {
|
loadFromCache.forEach(function (id) {
|
||||||
var model = cacheService.has(id) ?
|
modelResults[id] = this.cacheService.get(id);
|
||||||
updateModel(id, models[id]) : models[id];
|
}, this);
|
||||||
cacheService.put(id, model);
|
return modelResults;
|
||||||
});
|
}.bind(this));
|
||||||
}
|
|
||||||
|
|
||||||
// Expose the cache (for promise chaining)
|
|
||||||
function giveCache() {
|
|
||||||
return cacheService.all();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Look up if we have unknown IDs
|
|
||||||
if (neededIds.length > 0) {
|
|
||||||
return this.modelService.getModels(neededIds)
|
|
||||||
.then(cacheAll)
|
|
||||||
.then(giveCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just expose the cache directly
|
|
||||||
return fastPromise(cacheService.all());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return CachingModelDecorator;
|
return CachingModelDecorator;
|
||||||
|
@ -50,7 +50,7 @@ define(
|
|||||||
return function (model, id) {
|
return function (model, id) {
|
||||||
var capabilities = capabilityService.getCapabilities(model);
|
var capabilities = capabilityService.getCapabilities(model);
|
||||||
id = id || identifierService.generate();
|
id = id || identifierService.generate();
|
||||||
cacheService.put(id, model);
|
// cacheService.put(id, model);
|
||||||
return new DomainObjectImpl(id, model, capabilities);
|
return new DomainObjectImpl(id, model, capabilities);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ define(
|
|||||||
model.id = id;
|
model.id = id;
|
||||||
var capabilities = capabilityService.getCapabilities(model);
|
var capabilities = capabilityService.getCapabilities(model);
|
||||||
model.id = old_id;
|
model.id = old_id;
|
||||||
cacheService.put(id, model);
|
// cacheService.put(id, model);
|
||||||
return new DomainObjectImpl(id, model, capabilities);
|
return new DomainObjectImpl(id, model, capabilities);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user