mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-08 14:43:09 -06:00
Include key in cost
This commit is contained in:
parent
858cc61f92
commit
4a648a9052
|
|
@ -147,13 +147,19 @@ func (c *RistrettoCachePartition[K, V]) setWithCost(key K, value V, cost int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RistrettoCachePartition[K, V]) Set(key K, value V) {
|
func (c *RistrettoCachePartition[K, V]) Set(key K, value V) {
|
||||||
var cost int64
|
var keyCost int64
|
||||||
if cv, ok := any(value).(string); ok {
|
var valueCost int64
|
||||||
cost = int64(len(cv))
|
if ck, ok := any(key).(string); ok {
|
||||||
|
keyCost = int64(len(ck))
|
||||||
} else {
|
} else {
|
||||||
cost = int64(unsafe.Sizeof(value))
|
keyCost = int64(unsafe.Sizeof(key))
|
||||||
}
|
}
|
||||||
c.setWithCost(key, value, cost)
|
if cv, ok := any(value).(string); ok {
|
||||||
|
valueCost = int64(len(cv))
|
||||||
|
} else {
|
||||||
|
valueCost = int64(unsafe.Sizeof(value))
|
||||||
|
}
|
||||||
|
c.setWithCost(key, value, keyCost+valueCost)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *RistrettoCachePartition[K, V]) Unset(key K) {
|
func (c *RistrettoCachePartition[K, V]) Unset(key K) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue