Fetch does not return stale items
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package ccache
|
||||
|
||||
import (
|
||||
. "github.com/karlseguin/expect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
. "github.com/karlseguin/expect"
|
||||
)
|
||||
|
||||
type CacheTests struct{}
|
||||
@@ -22,6 +23,22 @@ func (_ CacheTests) DeletesAValue() {
|
||||
Expect(cache.Get("worm").Value()).To.Equal("sand")
|
||||
}
|
||||
|
||||
func (_ CacheTests) FetchesExpiredItems() {
|
||||
cache := New(Configure())
|
||||
fn := func() (interface{}, error) { return "moo-moo", nil }
|
||||
|
||||
cache.Set("beef", "moo", time.Second)
|
||||
Expect(cache.Get("beef").Value()).To.Equal("moo")
|
||||
|
||||
out, _ := cache.Fetch("beef", time.Second, fn)
|
||||
Expect(out.Value()).To.Equal("moo")
|
||||
|
||||
time.Sleep(2 * time.Second)
|
||||
|
||||
out2, _ := cache.Fetch("beef", time.Second, fn)
|
||||
Expect(out2.Value()).To.Equal("moo-moo")
|
||||
}
|
||||
|
||||
func (_ CacheTests) GCsTheOldestItems() {
|
||||
cache := New(Configure().ItemsToPrune(10))
|
||||
for i := 0; i < 500; i++ {
|
||||
|
Reference in New Issue
Block a user