lni / dragonboat

A feature complete and high performance multi-group Raft library in Go.
Apache License 2.0
4.99k stars 534 forks source link

PebbleDB openDB use Cache #237

Closed xkeyideal closed 2 years ago

xkeyideal commented 2 years ago
import "github.com/cockroachdb/pebble/internal/cache"

// Cache exports the cache.Cache type.
type Cache = cache.Cache

// NewCache creates a new cache of the specified size. Memory for the cache is
// allocated on demand, not during initialization. The cache is created with a
// reference count of 1. Each DB it is associated with adds a reference, so the
// creator of the cache should usually release their reference after the DB is
// created.
//
//   c := pebble.NewCache(...)
//   defer c.Unref()
//   d, err := pebble.Open(pebble.Options{Cache: c})
func NewCache(size int64) *cache.Cache {
    return cache.New(size)
}

Recommended usage:

cache := pebble.NewCache(cacheSize)
defer cache.Unref()