Skip to content

Commit

Permalink
https://github.com/water-fountains/datablue/issues/45
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf Hauser committed Mar 1, 2020
1 parent a84aad5 commit e29b1b5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions server/api/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import {extractProcessingErrors} from "./processing-errors.controller";
import {getImageInfo,getImgsOfCat} from "../services/wikimedia.service";
const haversine = require("haversine");
const _ = require('lodash');
import {MAX_IMG_SHOWN_IN_GALLERY, LAZY_ARTIST_NAME_LOADING_i41db} from "../../common/constants";
import {MAX_IMG_SHOWN_IN_GALLERY, LAZY_ARTIST_NAME_LOADING_i41db,
CACHE_FOR_HRS_i45db} from "../../common/constants";


// Configuration of Cache after https://www.npmjs.com/package/node-cache
const cityCache = new NodeCache( {
stdTTL: 60*60*2, // time till cache expires, in seconds
stdTTL: 60*60*CACHE_FOR_HRS_i45db, // time till cache expires, in seconds
checkperiod: 30, // how often to check for expiration, in seconds
deleteOnExpire: false, // on expire, we want the cache to be recreated not deleted
useClones: false // do not create a clone of the data when fetching from cache
Expand All @@ -54,7 +55,7 @@ cityCache.on('expired', (key, value)=>{
generateLocationData(key)
.then(fountainCollection=>{
// save newly generated fountainCollection to the cache
cityCache.set(key, fountainCollection, 60*60*2); // expire after two hours
cityCache.set(key, fountainCollection, 60*60*CACHE_FOR_HRS_i45db); // expire after two hours

// create a reduced version of the data as well
cityCache.set(key + '_essential', essenceOf(fountainCollection));
Expand All @@ -78,7 +79,7 @@ export class Controller {
generateLocationData(location_code)
.then(fountainCollection => {
// save new data to storage
cityCache.set(location_code, fountainCollection, 60 * 60 * 2); // expire after two hours
cityCache.set(location_code, fountainCollection, 60 * 60 * CACHE_FOR_HRS_i45db); // expire after two hours
// create a reduced version of the data as well
cityCache.set(location_code + '_essential', essenceOf(fountainCollection));
// also create list of processing errors (for proximap#206)
Expand Down Expand Up @@ -118,7 +119,7 @@ export class Controller {
generateLocationData(req.query.city)
.then(fountainCollection => {
// save new data to storage
cityCache.set(req.query.city, fountainCollection, 60*60*2);
cityCache.set(req.query.city, fountainCollection, 60*60*CACHE_FOR_HRS_i45db);

// create a reduced version of the data as well
let r_essential = essenceOf(fountainCollection);
Expand Down
5 changes: 3 additions & 2 deletions server/common/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @license
* (c) Copyright 2019 | MY-D Foundation | Created by Matthew Moy de Vitry
* (c) Copyright 2019 - 2020 | MY-D Foundation | Created by Matthew Moy de Vitry, Ralf Hauser
* Use of this code is governed by the GNU Affero General Public License (https://www.gnu.org/licenses/agpl-3.0)
* and the profit contribution agreement available at https://www.my-d.org/ProfitContributionAgreement
*/
Expand All @@ -14,4 +14,5 @@ export const PROP_STATUS_NOT_DEFINED = 'PROP_STATUS_NOT_DEFINED';
export const PROP_STATUS_NOT_AVAILABLE = 'PROP_STATUS_NOT_AVAILABLE';
export const MAX_IMG_SHOWN_IN_GALLERY = 50;
export const LAZY_ARTIST_NAME_LOADING_i41db = true;
export const LANGS = ['en', 'de', 'fr', 'it', 'tr', 'sr'];
export const LANGS = ['en', 'de', 'fr', 'it', 'tr', 'sr'];
export const CACHE_FOR_HRS_i45db = 48;

0 comments on commit e29b1b5

Please sign in to comment.