-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* perf improvements * perf improvements * remove comments from edgless init file * more perf fixes * remove fetch head call * fix * fix logs * fix logs * revert batch interval
- Loading branch information
1 parent
f1d6028
commit 3d5f926
Showing
17 changed files
with
241 additions
and
223 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
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,39 @@ | ||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/eko/gocache/lib/v4/cache" | ||
gethlog "github.com/ethereum/go-ethereum/log" | ||
"github.com/ethereum/go-ethereum/rlp" | ||
"github.com/obscuronet/go-obscuro/go/common/log" | ||
) | ||
|
||
func getCachedValue[V any](cache *cache.Cache[[]byte], logger gethlog.Logger, key any, onFailed func(any) (V, error)) (V, error) { | ||
value, err := cache.Get(context.Background(), key) | ||
if err != nil { | ||
// todo metrics for cache misses | ||
b, err := onFailed(key) | ||
if err != nil { | ||
return b, err | ||
} | ||
cacheValue(cache, logger, key, b) | ||
return b, err | ||
} | ||
|
||
v := new(V) | ||
err = rlp.DecodeBytes(value, v) | ||
return *v, err | ||
} | ||
|
||
func cacheValue(cache *cache.Cache[[]byte], logger gethlog.Logger, key any, v any) { | ||
encoded, err := rlp.EncodeToBytes(v) | ||
if err != nil { | ||
logger.Error("Could not encode value to store in cache", log.ErrKey, err) | ||
return | ||
} | ||
err = cache.Set(context.Background(), key, encoded) | ||
if err != nil { | ||
logger.Error("Could not store value in cache", log.ErrKey, err) | ||
} | ||
} |
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
Oops, something went wrong.