From 35044ad38a339ab825f38e71791874a54d34741b Mon Sep 17 00:00:00 2001 From: Bruno Carlin Date: Sat, 18 Jan 2025 01:37:41 +0100 Subject: [PATCH 1/3] fix: deadlock in tests --- cache.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/cache.go b/cache.go index b23880e..7c068f7 100644 --- a/cache.go +++ b/cache.go @@ -23,14 +23,13 @@ func (e entry[V]) isExpired() bool { // Cache is an in-memory key-value store. type Cache[K comparable, V any] struct { data map[K]entry[V] - mu *sync.RWMutex + mu sync.RWMutex } // New instantiate a new cache. func New[K comparable, V any]() *Cache[K, V] { return &Cache[K, V]{ data: make(map[K]entry[V]), - mu: &sync.RWMutex{}, } } @@ -47,9 +46,6 @@ func (c *Cache[K, V]) Put(key K, val V) { // // A 0 ttl value disables the expiration of the value. func (c *Cache[K, V]) PutTTL(key K, val V, ttl time.Duration) { - c.mu.Lock() - defer c.mu.Unlock() - if ttl == 0 { c.Put(key, val) @@ -58,6 +54,9 @@ func (c *Cache[K, V]) PutTTL(key K, val V, ttl time.Duration) { exp := time.Now().Add(ttl) + c.mu.Lock() + defer c.mu.Unlock() + c.data[key] = entry[V]{&exp, val} } From 2341b7e47314a971642920f63d44a36d48f80566 Mon Sep 17 00:00:00 2001 From: Bruno Carlin Date: Sat, 18 Jan 2025 01:38:53 +0100 Subject: [PATCH 2/3] finalize v0.1.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8981296..a4f9a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +## v0.1.1 (2025-01-18) + +* Fix a deadlock in tests + ## v0.1.0 (2025-01-18) * First version From 2ee001b76a470c90182f75a9a78f754d2e6dc658 Mon Sep 17 00:00:00 2001 From: Bruno Carlin Date: Sat, 8 Feb 2025 03:17:08 +0100 Subject: [PATCH 3/3] chore: update license --- LICENSE | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/LICENSE b/LICENSE index 1339f84..576c9bd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,10 +1,12 @@ -MIT License Copyright (c) 2021 Bruno Carlin +MIT License + +Copyright (c) 2021-2025 Bruno Carlin Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell c -pies of the Software, and to permit persons to whom the Software is +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all