cache.go 729 B

1234567891011121314151617181920212223242526272829303132333435
  1. package genPool
  2. import (
  3. "fmt"
  4. "github.com/goburrow/cache"
  5. )
  6. var (
  7. // 启服加载,不设置过期
  8. //
  9. // 产出池道具缓存 key:genPoolID_itemID, value:GenPoolItem
  10. genPoolItemCache = cache.New(
  11. cache.WithMaximumSize(-1),
  12. )
  13. )
  14. func buildKey(genPoolID int32, itemID int32) string {
  15. return fmt.Sprintf("%d_%d", genPoolID, itemID)
  16. }
  17. func GetGenPoolItemCache(genPoolID int32, itemID int32) (*GenPoolItem, bool) {
  18. key := buildKey(genPoolID, itemID)
  19. if v, ok := genPoolItemCache.GetIfPresent(key); ok {
  20. return v.(*GenPoolItem), true
  21. }
  22. return nil, false
  23. }
  24. func SetGenPoolItemCache(genPoolItem *GenPoolItem) {
  25. key := buildKey(genPoolItem.GenPoolID, genPoolItem.ItemID)
  26. genPoolItemCache.Put(key, genPoolItem)
  27. }