-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interfacing stateDB cache #646
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package statedb | ||
|
||
import "github.com/VictoriaMetrics/fastcache" | ||
|
||
// Cache interface the cache of stateDB | ||
type Cache interface { | ||
Set(k, v []byte) | ||
Get(dst, k []byte) []byte | ||
HasGet(dst, k []byte) ([]byte, bool) | ||
UpdateStats(s *fastcache.Stats) | ||
Get(k []byte) []byte | ||
Has(k []byte) ([]byte, bool) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package statedb | ||
|
||
import "github.com/VictoriaMetrics/fastcache" | ||
|
||
type LocalCache struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am gonna try to find a new name replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant for "wrapping fastcache.cache as statedb.FastCache" is to change the name of current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I will consider your comment in the next PR. |
||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing this file to
localcache.go
?