1
0
forked from MTSR/mapserver

add option to disable cache

This commit is contained in:
BuckarooBanzay 2023-10-11 17:33:41 +02:00
parent 0fd52738d0
commit ecad16ae7e
2 changed files with 58 additions and 44 deletions

View File

@ -65,7 +65,7 @@
"mapblockaccessor": {
"expiretime": "15s",
"purgetime": "30s",
"maxitems": 500
"maxitems": 0
},
"defaultoverlays": [
"mapserver_poi",
@ -75,5 +75,8 @@
"skins": {
"enableskinsdb": false,
"skinspath": ""
}
},
"worldpath": "./",
"datapath": "./",
"ColorsTxtPath": "./"
}

View File

@ -15,8 +15,11 @@ import (
var lock = &sync.RWMutex{}
func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.MapBlock, error) {
cache_enabled := a.maxcount > 0
key := getKey(pos)
if cache_enabled {
//maintenance
cacheBlocks.Set(float64(a.blockcache.ItemCount()))
if a.blockcache.ItemCount() > a.maxcount {
@ -66,6 +69,8 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.M
}
}
}
block, err := a.accessor.GetBlock(pos)
if err != nil {
return nil, err
@ -73,12 +78,16 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.M
if block == nil {
//no mapblock here
if cache_enabled {
cacheBlockCount.Inc()
a.blockcache.Set(key, nil, cache.DefaultExpiration)
}
return nil, nil
}
if cache_enabled {
getCacheMissCount.Inc()
}
mapblock, err := mapparser.Parse(block.Data)
if err != nil {
@ -87,8 +96,10 @@ func (a *MapBlockAccessor) GetMapBlock(pos *coords.MapBlockCoords) (*mapparser.M
a.Eventbus.Emit(eventbus.MAPBLOCK_RENDERED, types.NewParsedMapblock(mapblock, pos))
if cache_enabled {
cacheBlockCount.Inc()
a.blockcache.Set(key, mapblock, cache.DefaultExpiration)
}
return mapblock, nil
}