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