Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: go/src/infra/gae/libs/wrapper/memory/memcache.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added coverage files. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: go/src/infra/gae/libs/wrapper/memory/memcache.go
diff --git a/go/src/infra/gae/libs/wrapper/memory/memcache.go b/go/src/infra/gae/libs/wrapper/memory/memcache.go
index 19c2eebd6b75d395a2ce3cdca67b0d30997cab4b..2b48ca9c5842e256051a45f082791df216fad8b6 100644
--- a/go/src/infra/gae/libs/wrapper/memory/memcache.go
+++ b/go/src/infra/gae/libs/wrapper/memory/memcache.go
@@ -8,6 +8,7 @@ import (
"infra/gae/libs/wrapper"
"infra/gae/libs/wrapper/gae/commonErrors"
"infra/gae/libs/wrapper/unsafe"
+ "infra/libs/clock"
"sync"
"time"
@@ -29,8 +30,8 @@ type memcacheData struct {
type memcacheImpl struct {
wrapper.Memcache
- data *memcacheData
- timeNow func() time.Time
+ data *memcacheData
+ ctx context.Context
}
var (
@@ -61,7 +62,7 @@ func useMC(c context.Context) context.Context {
return &memcacheImpl{
wrapper.DummyMC(),
mcd,
- func() time.Time { return wrapper.GetTimeNow(ic) },
+ ic,
}
})
}
@@ -70,7 +71,7 @@ func (m *memcacheImpl) mkItemLocked(i *memcache.Item) *unsafe.Item {
m.data.casID++
var exp time.Duration
if i.Expiration != 0 {
- exp = time.Duration(m.timeNow().Add(i.Expiration).UnixNano())
+ exp = time.Duration(clock.Now(m.ctx).Add(i.Expiration).UnixNano())
}
newItem := unsafe.Item{
Key: i.Key,
@@ -97,7 +98,7 @@ func copyBack(i *unsafe.Item) *memcache.Item {
func (m *memcacheImpl) retrieve(key string) (*unsafe.Item, bool) {
ret, ok := m.data.items[key]
- if ok && ret.Expiration != 0 && ret.Expiration < time.Duration(m.timeNow().UnixNano()) {
+ if ok && ret.Expiration != 0 && ret.Expiration < time.Duration(clock.Now(m.ctx).UnixNano()) {
ret = nil
ok = false
delete(m.data.items, key)
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/datastore_data.go ('k') | go/src/infra/gae/libs/wrapper/memory/memcache_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698