Move LruCache to container package.

This commit is contained in:
Joachim Bauch 2025-12-10 16:29:24 +01:00
commit e478b93ba0
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
5 changed files with 13 additions and 12 deletions

View file

@ -19,7 +19,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package container
import (
"container/list"

View file

@ -19,7 +19,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package signaling
package container
import (
"strconv"

8
hub.go
View file

@ -179,7 +179,7 @@ type Hub struct {
// +checklocks:mu
virtualSessions map[PublicSessionId]uint64
decodeCaches []*LruCache[*SessionIdData]
decodeCaches []*container.LruCache[*SessionIdData]
mcu Mcu
mcuTimeout time.Duration
@ -307,9 +307,9 @@ func NewHub(ctx context.Context, config *goconf.ConfigFile, events AsyncEvents,
logger.Printf("No trusted proxies configured, only allowing for %s", trustedProxiesIps)
}
decodeCaches := make([]*LruCache[*SessionIdData], 0, numDecodeCaches)
decodeCaches := make([]*container.LruCache[*SessionIdData], 0, numDecodeCaches)
for range numDecodeCaches {
decodeCaches = append(decodeCaches, NewLruCache[*SessionIdData](decodeCacheSize))
decodeCaches = append(decodeCaches, container.NewLruCache[*SessionIdData](decodeCacheSize))
}
roomSessions, err := NewBuiltinRoomSessions(rpcClients)
@ -624,7 +624,7 @@ func (h *Hub) Reload(ctx context.Context, config *goconf.ConfigFile) {
h.rpcClients.Reload(config)
}
func (h *Hub) getDecodeCache(cache_key string) *LruCache[*SessionIdData] {
func (h *Hub) getDecodeCache(cache_key string) *container.LruCache[*SessionIdData] {
hash := fnv.New32a()
// Make sure we don't have a temporary allocation for the string -> []byte conversion.
hash.Write(unsafe.Slice(unsafe.StringData(cache_key), len(cache_key))) // nolint

View file

@ -815,9 +815,9 @@ func registerBackendHandlerUrl(t *testing.T, router *mux.Router, url string) {
func Benchmark_DecodePrivateSessionIdCached(b *testing.B) {
require := require.New(b)
decodeCaches := make([]*LruCache[*SessionIdData], 0, numDecodeCaches)
decodeCaches := make([]*container.LruCache[*SessionIdData], 0, numDecodeCaches)
for range numDecodeCaches {
decodeCaches = append(decodeCaches, NewLruCache[*SessionIdData](decodeCacheSize))
decodeCaches = append(decodeCaches, container.NewLruCache[*SessionIdData](decodeCacheSize))
}
backend := &Backend{
id: "compat",
@ -844,9 +844,9 @@ func Benchmark_DecodePrivateSessionIdCached(b *testing.B) {
func Benchmark_DecodePublicSessionIdCached(b *testing.B) {
require := require.New(b)
decodeCaches := make([]*LruCache[*SessionIdData], 0, numDecodeCaches)
decodeCaches := make([]*container.LruCache[*SessionIdData], 0, numDecodeCaches)
for range numDecodeCaches {
decodeCaches = append(decodeCaches, NewLruCache[*SessionIdData](decodeCacheSize))
decodeCaches = append(decodeCaches, container.NewLruCache[*SessionIdData](decodeCacheSize))
}
backend := &Backend{
id: "compat",

View file

@ -34,6 +34,7 @@ import (
"github.com/golang-jwt/jwt/v5"
signaling "github.com/strukturag/nextcloud-spreed-signaling"
"github.com/strukturag/nextcloud-spreed-signaling/container"
"github.com/strukturag/nextcloud-spreed-signaling/log"
)
@ -51,7 +52,7 @@ type tokensEtcd struct {
client *signaling.EtcdClient
tokenFormats atomic.Value
tokenCache *signaling.LruCache[*tokenCacheEntry]
tokenCache *container.LruCache[*tokenCacheEntry]
}
func NewProxyTokensEtcd(logger log.Logger, config *goconf.ConfigFile) (ProxyTokens, error) {
@ -67,7 +68,7 @@ func NewProxyTokensEtcd(logger log.Logger, config *goconf.ConfigFile) (ProxyToke
result := &tokensEtcd{
logger: logger,
client: client,
tokenCache: signaling.NewLruCache[*tokenCacheEntry](tokenCacheSize),
tokenCache: container.NewLruCache[*tokenCacheEntry](tokenCacheSize),
}
if err := result.load(config, false); err != nil {
return nil, err