forked from celestiaorg/celestia-node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(share/store/cache): Split accessor cache into recent and blockst…
…ore (celestiaorg#2656) Adds MultiCache. Replaces eds store cache with multicache containing 2 separate caches: - recently added edses (10 accessors, added on put only) - edses requested by ipld (128 accessors, added on request to blockstore from bitswap server)
- Loading branch information
Showing
5 changed files
with
87 additions
and
31 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
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