Skip to content

Commit 9fb18f6

Browse files
committed
Changed modifiedTime param for RefreshIfModifiedAfter to int64
1 parent e41e10a commit 9fb18f6

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

cache.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// including support for LRU, Segmented LRU and TinyLFU.
33
package cache
44

5-
import "time"
6-
75
// Key is any value which is comparable.
86
// See http://golang.org/ref/spec#Comparison_operators for details.
97
type Key interface{}
@@ -69,7 +67,7 @@ type LoadingCache interface {
6967
// RefreshIfModifiedAfter asynchronously reloads value for Key if the provided timestamp
7068
// indicates the data was modified after the entry was last loaded. If the entry doesn't exist,
7169
// it will synchronously load and block until the value is loaded.
72-
RefreshIfModifiedAfter(Key, time.Time)
70+
RefreshIfModifiedAfter(Key, int64)
7371
}
7472

7573
// LoaderFunc retrieves the value corresponding to given Key.

local.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ func (c *localCache) Refresh(k Key) {
243243
// RefreshIfModifiedAfter asynchronously reloads value for Key if the provided timestamp
244244
// indicates the data was modified after the entry was last loaded. If the entry doesn't exist,
245245
// it will synchronously load and block until the value is loaded.
246-
func (c *localCache) RefreshIfModifiedAfter(k Key, modifiedTime time.Time) {
246+
func (c *localCache) RefreshIfModifiedAfter(k Key, modifiedTime int64) {
247247
if c.loader == nil {
248248
return
249249
}
@@ -252,7 +252,7 @@ func (c *localCache) RefreshIfModifiedAfter(k Key, modifiedTime time.Time) {
252252
c.load(k)
253253
} else {
254254
// Only refresh if the data was modified after the entry was last loaded
255-
if modifiedTime.UnixNano() > en.getWriteTime() {
255+
if modifiedTime > en.getWriteTime() {
256256
c.refreshAsync(en)
257257
}
258258
}

local_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,23 +415,23 @@ func TestRefreshIfModifiedAfter(t *testing.T) {
415415

416416
// 1. Entry does not exist, should load synchronously.
417417
wg.Add(1)
418-
c.RefreshIfModifiedAfter(key, mockTime.now())
418+
c.RefreshIfModifiedAfter(key, mockTime.now().UnixNano())
419419
wg.Wait()
420420

421421
if loadCount != 1 {
422422
t.Fatalf("expected loadCount to be 1 after initial load, got %d", loadCount)
423423
}
424424

425425
// 2. Entry exists, but modifiedTime is not after entry's write time. Should not refresh.
426-
c.RefreshIfModifiedAfter(key, mockTime.now().Add(-1*time.Millisecond)) // modified time is before write time
426+
c.RefreshIfModifiedAfter(key, mockTime.now().Add(-1*time.Millisecond).UnixNano()) // modified time is before write time
427427
// No wg.Add/Wait as it should be synchronous and do nothing.
428428
if loadCount != 1 {
429429
t.Fatalf("expected loadCount to be 1 when not modified, got %d", loadCount)
430430
}
431431

432432
// 3. Entry exists, and modifiedTime is after entry's write time. Should refresh.
433433
wg.Add(1)
434-
c.RefreshIfModifiedAfter(key, mockTime.now().Add(1*time.Millisecond)) // modified time is after write time
434+
c.RefreshIfModifiedAfter(key, mockTime.now().Add(1*time.Millisecond).UnixNano()) // modified time is after write time
435435
wg.Wait()
436436
if loadCount != 2 {
437437
t.Fatalf("expected loadCount to be 2 after refresh, got %d", loadCount)
@@ -448,14 +448,14 @@ func TestRefreshIfModifiedAfter(t *testing.T) {
448448
t.Fatalf("unexpected get: %v %v", v, err)
449449
}
450450

451-
c.RefreshIfModifiedAfter(key2, mockTime.now()) // modified time is the same as write time
451+
c.RefreshIfModifiedAfter(key2, mockTime.now().UnixNano()) // modified time is the same as write time
452452
// No wg.Add/Wait as it should be synchronous and do nothing.
453453
if loadCount != 2 {
454454
t.Fatalf("expected loadCount to be 2 when not modified, got %d", loadCount)
455455
}
456456

457457
wg.Add(1)
458-
c.RefreshIfModifiedAfter(key, mockTime.now().Add(1*time.Millisecond)) // modified time is after write time
458+
c.RefreshIfModifiedAfter(key, mockTime.now().Add(1*time.Millisecond).UnixNano()) // modified time is after write time
459459
wg.Wait()
460460
if loadCount != 3 {
461461
t.Fatalf("expected loadCount to be 3 after refresh, got %d", loadCount)

0 commit comments

Comments
 (0)