mapserver/mapblockaccessor/mapblockaccessor.go

35 lines
698 B
Go
Raw Normal View History

2019-01-10 19:50:31 +03:00
package mapblockaccessor
import (
2019-01-13 18:37:03 +03:00
"fmt"
2019-01-10 19:50:31 +03:00
"mapserver/db"
2019-01-28 15:31:48 +03:00
"mapserver/eventbus"
2023-12-29 18:00:11 +03:00
"mapserver/types"
2019-01-28 15:31:48 +03:00
2019-01-11 11:07:31 +03:00
"time"
cache "github.com/patrickmn/go-cache"
2019-01-10 19:50:31 +03:00
)
type MapBlockAccessor struct {
2019-03-13 12:41:37 +03:00
accessor db.DBAccessor
blockcache *cache.Cache
Eventbus *eventbus.Eventbus
maxcount int
2019-01-11 11:07:31 +03:00
}
2023-12-29 18:00:11 +03:00
func getKey(pos *types.MapBlockCoords) string {
2019-01-11 11:07:31 +03:00
return fmt.Sprintf("Coord %d/%d/%d", pos.X, pos.Y, pos.Z)
2019-01-10 19:50:31 +03:00
}
2019-03-13 11:12:22 +03:00
func NewMapBlockAccessor(accessor db.DBAccessor, expiretime, purgetime time.Duration, maxcount int) *MapBlockAccessor {
2019-03-13 12:41:37 +03:00
blockcache := cache.New(expiretime, purgetime)
2019-01-11 11:07:31 +03:00
2019-01-28 15:31:48 +03:00
return &MapBlockAccessor{
2019-03-13 12:41:37 +03:00
accessor: accessor,
blockcache: blockcache,
Eventbus: eventbus.New(),
maxcount: maxcount,
2019-01-28 15:31:48 +03:00
}
2019-01-18 16:43:34 +03:00
}