Caching modules and functions.

This commit is contained in:
Ben Vanik 2013-12-25 06:43:16 -08:00
parent 20249c2290
commit 1c9fb97b5e
1 changed files with 33 additions and 4 deletions

View File

@ -61,6 +61,11 @@ module.service('DataSource', function($q) {
this.delegate = delegate; this.delegate = delegate;
this.online = false; this.online = false;
this.status = 'disconnected'; this.status = 'disconnected';
this.cache_ = {
modules: {},
functions: {}
};
}; };
inherits(DataSource, EventEmitter); inherits(DataSource, EventEmitter);
DataSource.prototype.open = function() {}; DataSource.prototype.open = function() {};
@ -80,10 +85,22 @@ module.service('DataSource', function($q) {
}; };
DataSource.prototype.getModule = function(moduleName) { DataSource.prototype.getModule = function(moduleName) {
return this.issue({ var d = $q.defer();
var cached = this.cache_.modules[moduleName];
if (cached) {
d.resolve(cached);
return d.promise;
}
this.issue({
command: 'cpu.get_module', command: 'cpu.get_module',
module: moduleName module: moduleName
}); }).then((function(result) {
this.cache_.modules[moduleName] = result;
d.resolve(result);
}).bind(this), (function(e) {
d.reject(e);
}).bind(this));
return d.promise;
}; };
DataSource.prototype.getFunctionList = function(moduleName) { DataSource.prototype.getFunctionList = function(moduleName) {
@ -94,10 +111,22 @@ module.service('DataSource', function($q) {
}; };
DataSource.prototype.getFunction = function(address) { DataSource.prototype.getFunction = function(address) {
return this.issue({ var d = $q.defer();
var cached = this.cache_.functions[address];
if (cached) {
d.resolve(cached);
return d.promise;
}
this.issue({
command: 'cpu.get_function', command: 'cpu.get_function',
address: address address: address
}); }).then((function(result) {
this.cache_.functions[address] = result;
d.resolve(result);
}).bind(this), (function(e) {
d.reject(e);
}).bind(this));
return d.promise;
}; };
DataSource.prototype.addBreakpoint = function(breakpoint) { DataSource.prototype.addBreakpoint = function(breakpoint) {