[release-branch.go1.4] create branch

This commit is contained in:
Andrew Gerrand 2014-11-17 11:23:56 +11:00
parent c13d674f5e
commit 3b1236a3b4
2 changed files with 16 additions and 10 deletions

1
README
View File

@ -8,3 +8,4 @@ Packages include a type-checker for Go and an implementation of the
Static Single Assignment form (SSA) representation for Go programs. Static Single Assignment form (SSA) representation for Go programs.
To submit changes to this repository, see http://golang.org/doc/contribute.html. To submit changes to this repository, see http://golang.org/doc/contribute.html.

View File

@ -40,7 +40,7 @@ func Now(c appengine.Context) uint64 {
func Tick(c appengine.Context) uint64 { func Tick(c appengine.Context) uint64 {
t, err := memcache.Increment(c, TimeKey, 1, newTime()) t, err := memcache.Increment(c, TimeKey, 1, newTime())
if err != nil { if err != nil {
c.Errorf("cache.Tick: %v", err) c.Errorf("cache: tick: %v", err)
return 0 return 0
} }
return t return t
@ -50,19 +50,21 @@ func Tick(c appengine.Context) uint64 {
// value. It reports whether it found the cache record and logs any errors to // value. It reports whether it found the cache record and logs any errors to
// the admin console. // the admin console.
func Get(r *http.Request, now uint64, name string, value interface{}) bool { func Get(r *http.Request, now uint64, name string, value interface{}) bool {
c := appengine.NewContext(r)
if now == 0 || r.FormValue(nocache) != "" { if now == 0 || r.FormValue(nocache) != "" {
c.Debugf("cache: skipping get: now=%v, nocache=%q", now, nocache)
return false return false
} }
c := appengine.NewContext(r)
key := fmt.Sprintf("%s.%d", name, now) key := fmt.Sprintf("%s.%d", name, now)
_, err := memcache.JSON.Get(c, key, value) _, err := memcache.JSON.Get(c, key, value)
if err == nil { switch err {
c.Debugf("cache hit %q", key) case nil:
c.Debugf("cache: get %q: hit", key)
return true return true
} case memcache.ErrCacheMiss:
c.Debugf("cache miss %q", key) c.Debugf("cache: get %q: cache miss", key)
if err != memcache.ErrCacheMiss { default:
c.Errorf("get cache %q: %v", key, err) c.Errorf("cache: get %q: %v", key, err)
} }
return false return false
} }
@ -70,10 +72,11 @@ func Get(r *http.Request, now uint64, name string, value interface{}) bool {
// Set puts value into memcache under name at time now. // Set puts value into memcache under name at time now.
// It logs any errors to the admin console. // It logs any errors to the admin console.
func Set(r *http.Request, now uint64, name string, value interface{}) { func Set(r *http.Request, now uint64, name string, value interface{}) {
c := appengine.NewContext(r)
if now == 0 || r.FormValue(nocache) != "" { if now == 0 || r.FormValue(nocache) != "" {
c.Debugf("cache: skipping set: now=%v, nocache=%q", now, nocache)
return return
} }
c := appengine.NewContext(r)
key := fmt.Sprintf("%s.%d", name, now) key := fmt.Sprintf("%s.%d", name, now)
err := memcache.JSON.Set(c, &memcache.Item{ err := memcache.JSON.Set(c, &memcache.Item{
Key: key, Key: key,
@ -81,6 +84,8 @@ func Set(r *http.Request, now uint64, name string, value interface{}) {
Expiration: expiry, Expiration: expiry,
}) })
if err != nil { if err != nil {
c.Errorf("set cache %q: %v", key, err) c.Errorf("cache: set %q: %v", key, err)
return
} }
c.Debugf("cache: set %q: ok", key)
} }