Skip to content

Commit 198c85e

Browse files
authored
file: load from file should allow configure maxBytes (#86)
It is needed to implement same behavior as load from file or new does (specifically this check https://github.com/VictoriaMetrics/fastcache/blob/e439f07b570777a09fb9b662e47bd52d895c349b/file.go#L133-L139) Related to https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8952/files
1 parent e439f07 commit 198c85e

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

file.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ func (c *Cache) SaveToFileConcurrent(filePath string, concurrency int) error {
7979
// LoadFromFile loads cache data from the given filePath.
8080
//
8181
// See SaveToFile* for saving cache data to file.
82-
func LoadFromFile(filePath string) (*Cache, error) {
83-
return load(filePath, 0)
82+
func LoadFromFile(filePath string, maxBytes int) (*Cache, error) {
83+
return load(filePath, maxBytes)
8484
}
8585

8686
// LoadFromFileOrNew tries loading cache data from the given filePath.

file_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestSaveLoadSmall(t *testing.T) {
2828
t.Fatalf("SaveToFile error: %s", err)
2929
}
3030

31-
c1, err := LoadFromFile(filePath)
31+
c1, err := LoadFromFile(filePath, 0)
3232
if err != nil {
3333
t.Fatalf("LoadFromFile error: %s", err)
3434
}
@@ -47,7 +47,7 @@ func TestSaveLoadSmall(t *testing.T) {
4747
}
4848

4949
func TestLoadFileNotExist(t *testing.T) {
50-
c, err := LoadFromFile(`non-existing-file`)
50+
c, err := LoadFromFile(`non-existing-file`, 0)
5151
if err == nil {
5252
t.Fatalf("LoadFromFile must return error; got nil")
5353
}
@@ -105,7 +105,7 @@ func testSaveLoadFile(t *testing.T, concurrency int) {
105105
c.Reset()
106106

107107
// Verify LoadFromFile
108-
c, err = LoadFromFile(filePath)
108+
c, err = LoadFromFile(filePath, 0)
109109
if err != nil {
110110
t.Fatalf("unexpected error: %s", err)
111111
}
@@ -240,7 +240,7 @@ func TestSaveLoadConcurrent(t *testing.T) {
240240
if err := c.SaveToFileConcurrent(filePath, 3); err != nil {
241241
panic(fmt.Errorf("cannot save cache to %q: %s", filePath, err))
242242
}
243-
cc, err := LoadFromFile(filePath)
243+
cc, err := LoadFromFile(filePath, 0)
244244
if err != nil {
245245
panic(fmt.Errorf("cannot load cache from %q: %s", filePath, err))
246246
}

file_timing_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func benchmarkLoadFromFile(b *testing.B, concurrency int) {
5151
b.ResetTimer()
5252
b.SetBytes(benchCacheSize)
5353
for i := 0; i < b.N; i++ {
54-
c, err := LoadFromFile(filePath)
54+
c, err := LoadFromFile(filePath, 0)
5555
if err != nil {
5656
b.Fatalf("cannot load cache from file: %s", err)
5757
}

0 commit comments

Comments
 (0)