-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-otel-group-to-dependabot
- Loading branch information
Showing
8 changed files
with
101 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cache | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/filecoin-project/dagstore/shard" | ||
) | ||
|
||
// DoubleCache represents a Cache that looks into multiple caches one by one. | ||
type DoubleCache struct { | ||
first, second Cache | ||
} | ||
|
||
// NewDoubleCache creates a new DoubleCache with the provided caches. | ||
func NewDoubleCache(first, second Cache) *DoubleCache { | ||
return &DoubleCache{ | ||
first: first, | ||
second: second, | ||
} | ||
} | ||
|
||
// Get looks for an item in all the caches one by one and returns the Cache found item. | ||
func (mc *DoubleCache) Get(key shard.Key) (Accessor, error) { | ||
ac, err := mc.first.Get(key) | ||
if err == nil { | ||
return ac, nil | ||
} | ||
return mc.second.Get(key) | ||
} | ||
|
||
// Remove removes an item from all underlying caches | ||
func (mc *DoubleCache) Remove(key shard.Key) error { | ||
err1 := mc.first.Remove(key) | ||
err2 := mc.second.Remove(key) | ||
return errors.Join(err1, err2) | ||
} | ||
|
||
func (mc *DoubleCache) First() Cache { | ||
return mc.first | ||
} | ||
|
||
func (mc *DoubleCache) Second() Cache { | ||
return mc.second | ||
} | ||
|
||
func (mc *DoubleCache) EnableMetrics() error { | ||
if err := mc.first.EnableMetrics(); err != nil { | ||
return err | ||
} | ||
return mc.second.EnableMetrics() | ||
} |
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