Skip to content

Commit

Permalink
Cache problem was resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
joseumbertomoreira committed Jun 28, 2017
1 parent 9fb13ea commit 8b6f268
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/client/controllers/temporal.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Application.controller('temporalController', function($rootScope, $scope, $locat
var lat = $scope.point.lat;
var county = $scope.point.county;
var url = window.location.origin+window.location.pathname
console.log(url);
$window.open(url+"service/kml?longitude="+lon+"&latitude="+lat+"&county="+county);
}

Expand Down Expand Up @@ -234,8 +235,8 @@ Application.controller('temporalController', function($rootScope, $scope, $locat

initFormViewVariables();
generateOptionYears($scope.config.initialYear, $scope.config.finalYear);
createModisChart()
createPrecipitationChart()
createModisChart();
createPrecipitationChart();
generateMaps();
$scope.counter = 0;

Expand Down
2 changes: 0 additions & 2 deletions src/client/controllers/tvi.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

Application.controller('TviController', function($rootScope, $scope, $location, $window, requester, util, $interval, $timeout) {


requester._get('login/user', function(result) {
if(!result.name) {
$location.path('login');
Expand Down Expand Up @@ -65,7 +64,6 @@ Application.controller('TviController', function($rootScope, $scope, $location,

requester._get('points/next-point', function(data) {
$scope.data = data;
console.log('ola', data.total, data.current)
$rootScope.total = data.total;
$rootScope.current = data.current;
$rootScope.count = data.count;
Expand Down
3 changes: 2 additions & 1 deletion src/client/controllers/tviSupervisor.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ Application.controller('tviSuper', function($rootScope, $scope, $location, $wind
});
}
$scope.getKml = function(){

console.log('oi')
var lon = $scope.data.lon;
var lat = $scope.data.lat;
var county = $scope.data.county;
var url = window.location.origin+window.location.pathname
console.log('oi')
$window.open(url+"service/kml?longitude="+lon+"&latitude="+lat+"&county="+county);
}

Expand Down
1 change: 1 addition & 0 deletions src/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = function(app) {
"clientDir": appRoot + "/../client",
"langDir": appRoot + "/lang",
"logDir": appRoot + "/log/",
"imgs": appRoot + "/images/",
"redis": {
"host": "localhost",
"port": 6379
Expand Down
2 changes: 1 addition & 1 deletion src/server/controllers/kml.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function(app) {
coordinates: lon+","+lat
});
response.setHeader('Content-type', 'text/xml')
response.setHeader('Content-disposition', 'attachment; filename=aquivo.kml');
response.setHeader('Content-disposition', 'attachment; filename=arquivo.kml');
response.write(content);
response.end()
});
Expand Down
6 changes: 3 additions & 3 deletions src/server/controllers/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ module.exports = function(app) {

app.on('socket-disconnect', function(socket) {

points.update({"_id": socket.request.session.currentPointId}, { $inc: { underInspection: -1}}, function(point) {

});
points.update({"_id": socket.request.session.currentPointId}, { $inc: { underInspection: -1}}, function(point) {
});
});

return Login;
Expand Down
1 change: 0 additions & 1 deletion src/server/controllers/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module.exports = function(app) {
var longitude = request.param('longitude');
longitude = '-49.6582';
latitude = '-16.4382';
console.log('longitude latitude',latitude, longitude);
var Url = "http://maps.lapig.iesa.ufg.br/time-series/TRMM_PRECIPITATION/values?_dc=1497123621159&longitude="+longitude+"&latitude="+latitude+"&mode=series&radius="

requester({
Expand Down
5 changes: 2 additions & 3 deletions src/server/controllers/tms.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ module.exports = function(app) {
url = url.replace(id,mapid);

cache.get(path, function(img) {

if(img){
if(img){
Internal.enhanceAndResponse(img, response)
} else {
var img = new Buffer([]);
Expand All @@ -69,7 +68,7 @@ module.exports = function(app) {
var data = new Buffer(data);
img = Buffer.concat([img, data])

}).on('end', function(data) {
}).on('end', function(data) {
Internal.enhanceAndResponse(img, response)
if(img.length > 0) {
cache.set(path, img)
Expand Down
33 changes: 33 additions & 0 deletions src/server/middleware/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ var util = require('util')
, redis = require('redis')
, request = require('request')
, async = require('async');
var fs = require('fs');
var exec = require('child_process').exec;

var count = 0
module.exports = function(app) {

var config = app.config;
Expand All @@ -11,6 +14,17 @@ module.exports = function(app) {
var Cache = {};

Cache.get = function(cacheKey, callback) {
var path = config.imgs+cacheKey+'/';
var img = cacheKey.slice(24, 29);
fs.readFile(path+img, function (err,data) {
if (!err && data) {
callback(data);
}else{
callback(undefined);
}
});

/*
redisClient.get(cacheKey, function(err, data) {
if(!err && data) {
var bitmap = new Buffer(data,'base64');
Expand All @@ -19,11 +33,30 @@ module.exports = function(app) {
callback(undefined);
}
});
*/

};

Cache.set = function(cacheKey, data){
cacheKey = cacheKey.substr(1);
exec('mkdir -p '+config.imgs+cacheKey, function(err, stdout, stderr){
var path = config.imgs+cacheKey+'/';
var img = cacheKey.slice(24, 29);
fs.writeFile(path+img, data, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});

})


/*
var img = new Buffer(data || '').toString('base64');
redisClient.set(cacheKey, img, function(){});
*/

}

Cache.del = function(keyPattern, data) {
Expand Down

2 comments on commit 8b6f268

@joseumbertomoreira
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #16

@joseumbertomoreira
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #1

Please sign in to comment.