Compare commits

...

8 commits

Author SHA1 Message Date
fb791d8b18 🔀 Merge branch 'r/0.5.2' into stable 2025-04-21 14:44:06 -05:00
4f1a18463d 📝 Update CHANGELOG 2025-04-21 14:43:33 -05:00
6dc48772c0 Add testable examples 2025-04-21 14:32:12 -05:00
d9f6417ca5 🔀 Merge tag 'v0.5.1' into develop
📄 Add LICENSE
2025-04-21 13:36:18 -05:00
d36db3937f 🔀 Merge branch 'r/0.5.1' into stable 2025-04-21 13:35:54 -05:00
15b1e6d1fd 📝 Update CHANGELOG 2025-04-21 13:35:04 -05:00
cfe2116fd4 📄 Add LICENSE 2025-04-21 12:30:17 -05:00
88a779a320 🔀 Merge tag 'v0.5.0' into develop
🚀 First release
2025-04-21 12:19:59 -05:00
4 changed files with 60 additions and 2 deletions

View file

@ -1,5 +1,9 @@
# Changelog
### [0.5.0] - 2025-04-21 - 🚀 Stable release!
## [0.5.2] - 2025-04-31 - ✅ Add testable examples
## [0.5.1] - 2025-04-31 - 📄 Add LICENSE
## [0.5.0] - 2025-04-21 - 🚀 Stable release!
Everything works.

21
LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2025, Dan Jones <danjones@goodevilgenius.org>.
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.

31
example_test.go Normal file
View file

@ -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
}

View file

@ -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)