From cfe2116fd410fe26ac2b34eac021e5f8407b064d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 21 Apr 2025 12:30:17 -0500 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=93=84=20Add=20LICENSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9f61e2e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2025, Dan Jones . + +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 +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 copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file From 15b1e6d1fdc256467663dc089e0be25dd76d6048 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 21 Apr 2025 13:35:04 -0500 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9D=20Update=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf9fb36..d0ed89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +### [0.5.1] - 2025-04-31 - 📄 Add LICENSE + ### [0.5.0] - 2025-04-21 - 🚀 Stable release! Everything works. From 6dc48772c0f8b26c9f727fdec9fe7fbd935099cc Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 21 Apr 2025 14:32:12 -0500 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=85=20Add=20testable=20examples?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example_test.go | 31 +++++++++++++++++++++++++++++++ ezcache_test.go | 4 +++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 example_test.go diff --git a/example_test.go b/example_test.go new file mode 100644 index 0000000..d8e1240 --- /dev/null +++ b/example_test.go @@ -0,0 +1,31 @@ +//nolint:perfsprint // Not that concerned about microoptimizations for test code +package ezcache_test + +import ( + "fmt" + "time" + + "codeberg.org/danjones000/ezcache" +) + +func Example() { + // Create a five minute cache. + cache, _ := ezcache.New(func(id uint8) (string, error) { + fmt.Println("Fetching new value for", id) + return fmt.Sprintf("%d", id), nil + }, 5*time.Minute) + + val, _ := cache.Get(5) + fmt.Println("Got value", val) + val, _ = cache.Get(5) + fmt.Println("Got value", val) + val, _ = cache.Get(4) + fmt.Println("Got value", val) + + // Output: + // Fetching new value for 5 + // Got value 5 + // Got value 5 + // Fetching new value for 4 + // Got value 4 +} diff --git a/ezcache_test.go b/ezcache_test.go index b713a75..0787885 100644 --- a/ezcache_test.go +++ b/ezcache_test.go @@ -1,3 +1,4 @@ +//nolint:perfsprint // Not that concerned about microoptimizations for test code package ezcache_test import ( @@ -69,7 +70,7 @@ func TestGetExpire(t *testing.T) { assert.True(t, hit) hit = false - time.Sleep(2) + time.Sleep(2 * time.Nanosecond) val, err = cache.Get(4) assert.NoError(t, err) assert.Equal(t, "4", val) @@ -77,6 +78,7 @@ func TestGetExpire(t *testing.T) { } func TestGetError(t *testing.T) { + //nolint:err113 // It's just a test for an error. cache, _ := ezcache.New(func(k uint8) (byte, error) { return 0, fmt.Errorf("Nope for %d", k) }, 1) _, err := cache.Get(4) From 4f1a18463dbbe5c9a931fc4f5af9bb21ff82cc6d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Mon, 21 Apr 2025 14:43:33 -0500 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9D=20Update=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0ed89d..77be94a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ # Changelog -### [0.5.1] - 2025-04-31 - 📄 Add LICENSE +## [0.5.2] - 2025-04-31 - ✅ Add testable examples -### [0.5.0] - 2025-04-21 - 🚀 Stable release! +## [0.5.1] - 2025-04-31 - 📄 Add LICENSE + +## [0.5.0] - 2025-04-21 - 🚀 Stable release! Everything works.