forked from dunglas/mercure
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: deprecate NewTopicSelectorStoreRistretto (dunglas#583)
- Loading branch information
Showing
7 changed files
with
54 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters