diff --git a/server/app/config.go b/server/app/config.go index 2757280..3fff624 100644 --- a/server/app/config.go +++ b/server/app/config.go @@ -10,16 +10,22 @@ import ( ) type Config struct { - Port int `json:"port"` - EnablePrometheus bool `json:"enableprometheus"` - EnableRendering bool `json:"enablerendering"` - Webdev bool `json:"webdev"` - WebApi *WebApiConfig `json:"webapi"` - Layers []*layer.Layer `json:"layers"` - RenderingFetchLimit int `json:"renderingfetchlimit"` - RenderingJobs int `json:"renderingjobs"` - RenderingQueue int `json:"renderingqueue"` - MapObjects *MapObjectConfig `json:"mapobjects"` + Port int `json:"port"` + EnablePrometheus bool `json:"enableprometheus"` + EnableRendering bool `json:"enablerendering"` + Webdev bool `json:"webdev"` + WebApi *WebApiConfig `json:"webapi"` + Layers []*layer.Layer `json:"layers"` + RenderingFetchLimit int `json:"renderingfetchlimit"` + RenderingJobs int `json:"renderingjobs"` + RenderingQueue int `json:"renderingqueue"` + MapObjects *MapObjectConfig `json:"mapobjects"` + MapBlockAccessorCfg *MapBlockAccessorConfig `json:"mapblockaccessor"` +} + +type MapBlockAccessorConfig struct { + Expiretime string `json:"expiretime"` + Purgetime string `json:"purgetime"` } type MapObjectConfig struct { @@ -106,6 +112,11 @@ func ParseConfig(filename string) (*Config, error) { ATM: true, } + mapblockaccessor := MapBlockAccessorConfig{ + Expiretime: "500ms", + Purgetime: "1000ms", + } + cfg := Config{ Port: 8080, EnableRendering: true, @@ -117,6 +128,7 @@ func ParseConfig(filename string) (*Config, error) { RenderingJobs: runtime.NumCPU(), RenderingQueue: 100, MapObjects: &mapobjs, + MapBlockAccessorCfg: &mapblockaccessor, } info, err := os.Stat(filename) diff --git a/server/app/setup.go b/server/app/setup.go index b32bda7..869021f 100644 --- a/server/app/setup.go +++ b/server/app/setup.go @@ -13,12 +13,13 @@ import ( "mapserver/tiledb" "mapserver/tilerenderer" "mapserver/worldconfig" - - "github.com/sirupsen/logrus" + "time" "io/ioutil" "os" + "github.com/sirupsen/logrus" + "errors" ) @@ -58,7 +59,17 @@ func Setup(p params.ParamsType, cfg *Config) *App { } //mapblock accessor - a.BlockAccessor = mapblockaccessor.NewMapBlockAccessor(a.Blockdb) + expireDuration, err := time.ParseDuration(cfg.MapBlockAccessorCfg.Expiretime) + if err != nil { + panic(err) + } + + purgeDuration, err := time.ParseDuration(cfg.MapBlockAccessorCfg.Purgetime) + if err != nil { + panic(err) + } + + a.BlockAccessor = mapblockaccessor.NewMapBlockAccessor(a.Blockdb, expireDuration, purgeDuration) //color mapping a.Colormapping = colormapping.NewColorMapping() diff --git a/server/mapblockaccessor/mapblockaccessor.go b/server/mapblockaccessor/mapblockaccessor.go index c1d224e..20b7845 100644 --- a/server/mapblockaccessor/mapblockaccessor.go +++ b/server/mapblockaccessor/mapblockaccessor.go @@ -21,8 +21,8 @@ func getKey(pos *coords.MapBlockCoords) string { return fmt.Sprintf("Coord %d/%d/%d", pos.X, pos.Y, pos.Z) } -func NewMapBlockAccessor(accessor db.DBAccessor) *MapBlockAccessor { - c := cache.New(500*time.Millisecond, 1000*time.Millisecond) +func NewMapBlockAccessor(accessor db.DBAccessor, expiretime, purgetime time.Duration) *MapBlockAccessor { + c := cache.New(expiretime, purgetime) return &MapBlockAccessor{ accessor: accessor, diff --git a/server/mapblockaccessor/mapblockaccessor_test.go b/server/mapblockaccessor/mapblockaccessor_test.go index dc68d32..0bcc037 100644 --- a/server/mapblockaccessor/mapblockaccessor_test.go +++ b/server/mapblockaccessor/mapblockaccessor_test.go @@ -1,13 +1,15 @@ package mapblockaccessor import ( - "github.com/sirupsen/logrus" "io/ioutil" "mapserver/coords" "mapserver/db/sqlite" "mapserver/testutils" "os" "testing" + "time" + + "github.com/sirupsen/logrus" ) func TestSimpleAccess(t *testing.T) { @@ -30,7 +32,7 @@ func TestSimpleAccess(t *testing.T) { panic(err) } - cache := NewMapBlockAccessor(a) + cache := NewMapBlockAccessor(a, 500*time.Millisecond, 1000*time.Millisecond) mb, err := cache.GetMapBlock(coords.NewMapBlockCoords(0, 0, 0)) if err != nil {