Skip to content

Commit 2adb804

Browse files
fliskyYin Jifeng
authored and
Yin Jifeng
committed
give a way to access the stale cache
1 parent e16ff42 commit 2adb804

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

bigcache_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,14 +934,20 @@ func TestBigCache_GetWithInfo(t *testing.T) {
934934

935935
// when
936936
data, resp, err := cache.GetWithInfo(key)
937+
938+
// then
937939
assertEqual(t, []byte(value), data)
938940
noError(t, err)
939941
assertEqual(t, Response{}, resp)
942+
943+
// when
940944
clock.set(5)
945+
946+
// then
941947
data, resp, err = cache.GetWithInfo(key)
942948
assertEqual(t, err, nil)
943949
assertEqual(t, Response{EntryStatus: Expired}, resp)
944-
assertEqual(t, []byte(nil), data)
950+
assertEqual(t, []byte(value), data)
945951
}
946952

947953
type mockedLogger struct {

shard.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@ func (s *cacheShard) getWithInfo(key string, hashedKey uint64) (entry []byte, re
4949
return nil, resp, ErrEntryNotFound
5050
}
5151

52+
entry = readEntry(wrappedEntry)
5253
oldestTimeStamp := readTimestampFromEntry(wrappedEntry)
54+
s.lock.RUnlock()
55+
s.hit(hashedKey)
5356
if currentTime-oldestTimeStamp >= s.lifeWindow {
54-
s.lock.RUnlock()
5557
resp.EntryStatus = Expired
56-
return nil, resp, nil
5758
}
58-
entry = readEntry(wrappedEntry)
59-
s.lock.RUnlock()
60-
s.hit(hashedKey)
6159
return entry, resp, nil
6260
}
6361

0 commit comments

Comments
 (0)