]> Cypherpunks repositories - gostls13.git/commitdiff
dashboard: use 'ok' instead of 'hit' or 'miss' for bool return vals
authorAndrew Gerrand <adg@golang.org>
Wed, 21 Dec 2011 10:12:03 +0000 (21:12 +1100)
committerAndrew Gerrand <adg@golang.org>
Wed, 21 Dec 2011 10:12:03 +0000 (21:12 +1100)
R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5505054

misc/dashboard/app/build/cache.go
misc/dashboard/app/build/handler.go

index 34d39ac92cfde8e7317fea249d037cc808c06a53..799a9c11ae55d58f3b4f1d34bfc796e10b1b0d3f 100644 (file)
@@ -32,8 +32,8 @@ func invalidateCache(c appengine.Context) {
 
 // cachedTodo gets the specified todo cache entry (if it exists) from the
 // shared todo cache.
-func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) {
-       t, _ := todoCache(c)
+func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, ok bool) {
+       t := todoCache(c)
        if t == nil {
                return nil, false
        }
@@ -41,7 +41,7 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) {
        if todos == nil {
                return nil, false
        }
-       todo, hit = todos[todoKey]
+       todo, ok = todos[todoKey]
        return
 }
 
@@ -50,17 +50,14 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) {
 func cacheTodo(c appengine.Context, todoKey string, todo *Todo) {
        // Get the todo cache record (or create a new one).
        newItem := false
-       t, miss := todoCache(c)
-       if miss {
+       t := todoCache(c)
+       if t == nil {
                newItem = true
                t = &memcache.Item{
                        Key:   todoCacheKey,
                        Value: []byte("{}"), // default is an empty JSON object
                }
        }
-       if t == nil {
-               return
-       }
 
        // Unmarshal the JSON value.
        todos := unmarshalTodo(c, t)
@@ -98,15 +95,15 @@ func cacheTodo(c appengine.Context, todoKey string, todo *Todo) {
 }
 
 // todoCache gets the todo cache record from memcache (if it exists).
-func todoCache(c appengine.Context) (item *memcache.Item, miss bool) {
+func todoCache(c appengine.Context) *memcache.Item {
        t, err := memcache.Get(c, todoCacheKey)
-       if err == memcache.ErrCacheMiss {
-               return nil, true
-       } else if err != nil {
-               c.Errorf("get todo cache: %v", err)
-               return nil, false
+       if err != nil {
+               if err != memcache.ErrCacheMiss {
+                       c.Errorf("get todo cache: %v", err)
+               }
+               return nil
        }
-       return t, false
+       return t
 }
 
 // unmarshalTodo decodes the given item's memcache value into a map.
index 28a3889d48f4276b63ddbdd37223dbb06dd7d315..a4d52853ae707a9a3a2860f8e7e5570531a320c2 100644 (file)
@@ -150,7 +150,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
        c := appengine.NewContext(r)
 
        todoKey := r.Form.Encode()
-       if t, hit := cachedTodo(c, todoKey); hit {
+       if t, ok := cachedTodo(c, todoKey); ok {
                c.Debugf("cache hit")
                return t, nil
        }