mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-11-08 11:10:27 +01:00
LevelDB: Do not create cache if cache size <= 0.
This commit is contained in:
parent
787ea5d0ee
commit
2e47262ce8
18
leveldb.go
18
leveldb.go
|
@ -23,13 +23,21 @@ type LevelDBSession struct {
|
|||
}
|
||||
|
||||
func NewLeveDBBackend(path string, cacheSize int) (ldb *LevelDBBackend, err error) {
|
||||
cache := leveldb.NewLRUCache(cacheSize * 1024 * 1024)
|
||||
opts := leveldb.NewOptions()
|
||||
opts.SetCache(cache)
|
||||
|
||||
var cache *leveldb.Cache
|
||||
if cacheSize > 0 {
|
||||
cache = leveldb.NewLRUCache(cacheSize * 1024 * 1024)
|
||||
opts.SetCache(cache)
|
||||
}
|
||||
|
||||
opts.SetCreateIfMissing(true)
|
||||
|
||||
var db *leveldb.DB
|
||||
if db, err = leveldb.Open(path, opts); err != nil {
|
||||
cache.Close()
|
||||
if cache != nil {
|
||||
cache.Close()
|
||||
}
|
||||
return
|
||||
}
|
||||
ldb = &LevelDBBackend{
|
||||
|
@ -63,7 +71,9 @@ func (ldbs *LevelDBSession) Close() error {
|
|||
|
||||
func (ldb *LevelDBBackend) Shutdown() error {
|
||||
ldb.db.Close()
|
||||
ldb.cache.Close()
|
||||
if ldb.cache != nil {
|
||||
ldb.cache.Close()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user