-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #646 from aidan-kwon/0827-trieCache
Interfacing stateDB cache
- Loading branch information
Showing
6 changed files
with
95 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package statedb | ||
|
||
// Cache interface the cache of stateDB | ||
type Cache interface { | ||
Set(k, v []byte) | ||
Get(k []byte) []byte | ||
Has(k []byte) ([]byte, bool) | ||
} |
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,32 @@ | ||
package statedb | ||
|
||
import "github.com/VictoriaMetrics/fastcache" | ||
|
||
type LocalCache struct { | ||
cache *fastcache.Cache | ||
} | ||
|
||
func NewLocalCache(maxBytes int) Cache { | ||
return &LocalCache{ | ||
cache: fastcache.New(maxBytes), | ||
} | ||
} | ||
|
||
func (l *LocalCache) Get(k []byte) []byte { | ||
return l.cache.Get(nil, k) | ||
} | ||
|
||
func (l *LocalCache) Set(k, v []byte) { | ||
l.cache.Set(k, v) | ||
} | ||
|
||
func (l *LocalCache) Has(k []byte) ([]byte, bool) { | ||
return l.cache.HasGet(nil, k) | ||
} | ||
|
||
func (l *LocalCache) UpdateStats() fastcache.Stats { | ||
var stats fastcache.Stats | ||
l.cache.UpdateStats(&stats) | ||
|
||
return stats | ||
} |
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