update cache mechanism to handle forced profile

This commit is contained in:
Emil Tin 2017-09-19 09:32:52 +02:00 committed by Patrick Niklaus
parent 999211ed9c
commit 59f8330db4
3 changed files with 8 additions and 5 deletions

View File

@ -20,11 +20,11 @@ module.exports = {
}); });
}, },
hashOfFile: (path, cb) => { hashOfFile: (path, additional_content, cb) => {
fs.readFile(path, (err, result) => { fs.readFile(path, (err, result) => {
if (err) return cb(err); if (err) return cb(err);
let checksum = crypto.createHash('md5'); let checksum = crypto.createHash('md5');
checksum.update(result); checksum.update(result + (additional_content || "") );
cb(null, checksum.digest('hex')); cb(null, checksum.digest('hex'));
}); });
} }

View File

@ -28,13 +28,16 @@ module.exports = function() {
let uri = feature.getUri(); let uri = feature.getUri();
// setup cache for feature data // setup cache for feature data
hash.hashOfFile(uri, (err, hash) => { // if OSRM_PROFILE is set to force a specific profile, then
// include the profile name in the hash of the profile file
hash.hashOfFile(uri, this.OSRM_PROFILE, (err, hash) => {
if (err) return callback(err); if (err) return callback(err);
// shorten uri to be realtive to 'features/' // shorten uri to be realtive to 'features/'
let featurePath = path.relative(path.resolve('./features'), uri); let featurePath = path.relative(path.resolve('./features'), uri);
// bicycle/bollards/{HASH}/ // bicycle/bollards/{HASH}/
let featureID = path.join(featurePath, hash); let featureID = path.join(featurePath, hash);
let featureCacheDirectory = this.getFeatureCacheDirectory(featureID); let featureCacheDirectory = this.getFeatureCacheDirectory(featureID);
let featureProcessedCacheDirectory = this.getFeatureProcessedCacheDirectory(featureCacheDirectory, this.osrmHash); let featureProcessedCacheDirectory = this.getFeatureProcessedCacheDirectory(featureCacheDirectory, this.osrmHash);
this.featureIDs[uri] = featureID; this.featureIDs[uri] = featureID;

View File

@ -45,7 +45,7 @@ module.exports = function () {
this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000; this.OSRM_PORT = process.env.OSRM_PORT && parseInt(process.env.OSRM_PORT) || 5000;
this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT; this.HOST = 'http://127.0.0.1:' + this.OSRM_PORT;
this.OSRM_PROFILE = process.env.PROFILE this.OSRM_PROFILE = process.env.OSRM_PROFILE
if (this.PLATFORM_WINDOWS) { if (this.PLATFORM_WINDOWS) {
this.TERMSIGNAL = 9; this.TERMSIGNAL = 9;