Browse Source

CustomCategory: cache categories

master
parent
commit
045ec83d81
  1. 11
      src/customCategory.js

11
src/customCategory.js

@ -5,6 +5,8 @@ const md5 = require('md5')
const OpenStreetBrowserLoader = require('./OpenStreetBrowserLoader')
const cache = {}
class CustomCategoryRepository {
constructor () {
}
@ -17,6 +19,10 @@ class CustomCategoryRepository {
}
getCategory (id, options, callback) {
if (id in cache) {
return callback(null, yaml.load(cache[id]))
}
ajax('customCategory', { id }, (result) => {
callback(null, yaml.load(result))
})
@ -75,15 +81,16 @@ class CustomCategory {
applyContent (content) {
this.content = content
const id = 'custom/' + md5(content)
const id = md5(content)
const data = yaml.load(content)
cache[id] = content
if (this.category) {
this.category.remove()
this.category = null
}
OpenStreetBrowserLoader.getCategoryFromData(id, {}, data, (err, category) => {
OpenStreetBrowserLoader.getCategoryFromData('custom/' + id, {}, data, (err, category) => {
if (err) {
return global.alert(err)
}

Loading…
Cancel
Save