-
-
Notifications
You must be signed in to change notification settings - Fork 276
/
topic_selector_ristretto.go
34 lines (28 loc) 路 939 Bytes
/
topic_selector_ristretto.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package mercure
import (
"fmt"
"github.com/dgraph-io/ristretto"
)
// Gather stats to find the best default values.
const (
TopicSelectorStoreRistrettoDefaultCacheNumCounters = int64(6e7)
TopicSelectorStoreRistrettoCacheMaxCost = int64(1e8) // 100 MB
)
// NewTopicSelectorStoreRistretto creates a TopicSelectorStore instance with a ristretto cache.
// See https://github.com/dgraph-io/ristretto, set values to 0 to disable.
//
// Deprecated: use NewTopicSelectorStoreLRU instead.
func NewTopicSelectorStoreRistretto(cacheNumCounters, cacheMaxCost int64) (*TopicSelectorStore, error) {
if cacheNumCounters == 0 {
return &TopicSelectorStore{}, nil
}
cache, err := ristretto.NewCache(&ristretto.Config{
NumCounters: cacheNumCounters,
MaxCost: cacheMaxCost,
BufferItems: 64,
})
if err != nil {
return nil, fmt.Errorf("unable to create cache: %w", err)
}
return &TopicSelectorStore{cache: cache}, nil
}