mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
More key tweaks (#1116)
This commit is contained in:
parent
ec7718e7f8
commit
079d8fe8fb
6 changed files with 29 additions and 16 deletions
|
@ -2,6 +2,7 @@ package caching
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
@ -23,9 +24,17 @@ func (c Caches) GetServerKey(
|
|||
request gomatrixserverlib.PublicKeyLookupRequest,
|
||||
) (gomatrixserverlib.PublicKeyLookupResult, bool) {
|
||||
key := fmt.Sprintf("%s/%s", request.ServerName, request.KeyID)
|
||||
now := gomatrixserverlib.AsTimestamp(time.Now())
|
||||
val, found := c.ServerKeys.Get(key)
|
||||
if found && val != nil {
|
||||
if keyLookupResult, ok := val.(gomatrixserverlib.PublicKeyLookupResult); ok {
|
||||
if !keyLookupResult.WasValidAt(now, true) {
|
||||
// We appear to be past the key validity so don't return this
|
||||
// with the results. This ensures that the cache doesn't return
|
||||
// values that are not useful to us.
|
||||
c.ServerKeys.Unset(key)
|
||||
return gomatrixserverlib.PublicKeyLookupResult{}, false
|
||||
}
|
||||
return keyLookupResult, true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,4 +12,5 @@ type Caches struct {
|
|||
type Cache interface {
|
||||
Get(key string) (value interface{}, ok bool)
|
||||
Set(key string, value interface{})
|
||||
Unset(key string)
|
||||
}
|
||||
|
|
|
@ -68,6 +68,13 @@ func (c *InMemoryLRUCachePartition) Set(key string, value interface{}) {
|
|||
c.lru.Add(key, value)
|
||||
}
|
||||
|
||||
func (c *InMemoryLRUCachePartition) Unset(key string) {
|
||||
if !c.mutable {
|
||||
panic(fmt.Sprintf("invalid use of immutable cache tries to unset value of %q", key))
|
||||
}
|
||||
c.lru.Remove(key)
|
||||
}
|
||||
|
||||
func (c *InMemoryLRUCachePartition) Get(key string) (value interface{}, ok bool) {
|
||||
return c.lru.Get(key)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue