Compare commits
No commits in common. "fb791d8b18cbfc57e305d8e78a96cea94a6c219e" and "d36db3937f43348a956970a06b1e6651054c46d7" have entirely different histories.
fb791d8b18
...
d36db3937f
3 changed files with 3 additions and 38 deletions
|
|
@ -1,9 +1,7 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## [0.5.2] - 2025-04-31 - ✅ Add testable examples
|
### [0.5.1] - 2025-04-31 - 📄 Add LICENSE
|
||||||
|
|
||||||
## [0.5.1] - 2025-04-31 - 📄 Add LICENSE
|
### [0.5.0] - 2025-04-21 - 🚀 Stable release!
|
||||||
|
|
||||||
## [0.5.0] - 2025-04-21 - 🚀 Stable release!
|
|
||||||
|
|
||||||
Everything works.
|
Everything works.
|
||||||
|
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
//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
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
//nolint:perfsprint // Not that concerned about microoptimizations for test code
|
|
||||||
package ezcache_test
|
package ezcache_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
@ -70,7 +69,7 @@ func TestGetExpire(t *testing.T) {
|
||||||
assert.True(t, hit)
|
assert.True(t, hit)
|
||||||
|
|
||||||
hit = false
|
hit = false
|
||||||
time.Sleep(2 * time.Nanosecond)
|
time.Sleep(2)
|
||||||
val, err = cache.Get(4)
|
val, err = cache.Get(4)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, "4", val)
|
assert.Equal(t, "4", val)
|
||||||
|
|
@ -78,7 +77,6 @@ func TestGetExpire(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetError(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)
|
cache, _ := ezcache.New(func(k uint8) (byte, error) { return 0, fmt.Errorf("Nope for %d", k) }, 1)
|
||||||
|
|
||||||
_, err := cache.Get(4)
|
_, err := cache.Get(4)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue