Skip to content

Commit

Permalink
Add (very) simple caching
Browse files Browse the repository at this point in the history
  • Loading branch information
msrb committed Apr 21, 2017
1 parent aa892c2 commit e8c81fa
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,16 @@ if (fs.existsSync(rc_file)) {

let DiagnosticsEngines = [SecurityEngine];

// TODO: in-memory caching only, this needs to be more robust
let metadataCache = new Map();

let get_metadata = (ecosystem, name, version, cb) => {
let cacheKey = ecosystem + " " + name + " " + version;
let metadata = metadataCache[cacheKey];
if (metadata != null) {
cb(metadata);
return
}
let part = [ecosystem, name, version].join('/');
let query = `${config.server_url}/component-analyses/${part}/`;

Expand All @@ -195,6 +204,7 @@ let get_metadata = (ecosystem, name, version, cb) => {
res.on('end', function(){
if (this.statusCode == 200 || this.statusCode == 202) {
let response = JSON.parse(body);
metadataCache[cacheKey] = response;
cb(response);
} else {
cb(null);
Expand Down

0 comments on commit e8c81fa

Please sign in to comment.