-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
op-node: receipts cache limit by volume
- Loading branch information
1 parent
e62988a
commit 630cc4c
Showing
3 changed files
with
80 additions
and
8 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,30 @@ | ||
package caching | ||
|
||
type VolumeFn func(key interface{}, value interface{}) int | ||
|
||
// VolumeLimit is used to limit the total volume of the cache. | ||
type VolumeLimit struct { | ||
volume int | ||
limit int | ||
volumeFn VolumeFn | ||
} | ||
|
||
func NewVolumeLimit(limit int, volumeFn VolumeFn) VolumeLimit { | ||
return VolumeLimit{ | ||
volume: 0, | ||
limit: limit, | ||
volumeFn: volumeFn, | ||
} | ||
} | ||
|
||
func (v *VolumeLimit) Add(key interface{}, value interface{}) { | ||
v.volume += v.volumeFn(key, value) | ||
} | ||
|
||
func (v *VolumeLimit) Remove(key interface{}, value interface{}) { | ||
v.volume -= v.volumeFn(key, value) | ||
} | ||
|
||
func (v *VolumeLimit) OverLimit() bool { | ||
return v.volume > v.limit | ||
} |
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