Skip to content

Commit 3a8dae8

Browse files
committed
vendor fastCache to use as ledger cache
FastCache is chosen as the caching library. FAB-15537 #done Change-Id: I4733fa64872e5743f38d1dd46adf1fad6d70d59e Signed-off-by: senthil <cendhu@gmail.com>
1 parent 53a1bce commit 3a8dae8

File tree

17 files changed

+1729
-0
lines changed

17 files changed

+1729
-0
lines changed

Gopkg.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,7 @@ noverify = [
188188
[[constraint]]
189189
branch = "master"
190190
name = "github.com/hyperledger/fabric-chaincode-go"
191+
192+
[[constraint]]
193+
name = "github.com/VictoriaMetrics/fastcache"
194+
version = "1.4.6"
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package statedb
8+
9+
import (
10+
"github.com/VictoriaMetrics/fastcache"
11+
)
12+
13+
// Cache holds both the system and user cache
14+
type Cache struct {
15+
sysCache *fastcache.Cache
16+
usrCache *fastcache.Cache
17+
}
18+
19+
// New creates a Cache. The cache consists of both system state cache (for lscc, _lifecycle)
20+
// and user state cache (for all user deployed chaincodes). The size of the
21+
// system state cache is 64 MB, by default. The size of the user state cache, in terms of MB, is
22+
// specified via usrCacheSize parameter. Note that the fastcache allocates memory
23+
// only in the multiples of 32 MB (due to 512 buckets & an equal number of 64 KB chunks per bucket).
24+
// If the usrCacheSize is not a multiple of 32 MB, the fastcache would round the size
25+
// to the next multiple of 32 MB.
26+
func New(usrCacheSize int) *Cache {
27+
cache := &Cache{}
28+
// By default, 64 MB is allocated for the system cache
29+
cache.sysCache = fastcache.New(64 * 1024 * 1024)
30+
31+
// User passed size is used to allocate memory for the user cache
32+
if usrCacheSize <= 0 {
33+
return cache
34+
}
35+
cache.usrCache = fastcache.New(usrCacheSize * 1024 * 1024)
36+
return cache
37+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package statedb
8+
9+
import (
10+
"testing"
11+
12+
"github.com/VictoriaMetrics/fastcache"
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestNewCache(t *testing.T) {
17+
cache := New(10)
18+
expectedCache := &Cache{
19+
sysCache: fastcache.New(64 * 1024 * 1024),
20+
usrCache: fastcache.New(10 * 1024 * 1024),
21+
}
22+
assert.Equal(t, expectedCache, cache)
23+
24+
cache = New(0)
25+
expectedCache = &Cache{
26+
sysCache: fastcache.New(64 * 1024 * 1024),
27+
usrCache: nil,
28+
}
29+
assert.Equal(t, expectedCache, cache)
30+
}

vendor/github.com/VictoriaMetrics/fastcache/LICENSE

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/VictoriaMetrics/fastcache/bigcache.go

Lines changed: 152 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)