Commit 351f7efe authored by Andrew Gerrand's avatar Andrew Gerrand

dashboard: use 'ok' instead of 'hit' or 'miss' for bool return vals

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/5505054
parent efa2246e
...@@ -32,8 +32,8 @@ func invalidateCache(c appengine.Context) { ...@@ -32,8 +32,8 @@ func invalidateCache(c appengine.Context) {
// cachedTodo gets the specified todo cache entry (if it exists) from the // cachedTodo gets the specified todo cache entry (if it exists) from the
// shared todo cache. // shared todo cache.
func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) { func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, ok bool) {
t, _ := todoCache(c) t := todoCache(c)
if t == nil { if t == nil {
return nil, false return nil, false
} }
...@@ -41,7 +41,7 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) { ...@@ -41,7 +41,7 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) {
if todos == nil { if todos == nil {
return nil, false return nil, false
} }
todo, hit = todos[todoKey] todo, ok = todos[todoKey]
return return
} }
...@@ -50,17 +50,14 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) { ...@@ -50,17 +50,14 @@ func cachedTodo(c appengine.Context, todoKey string) (todo *Todo, hit bool) {
func cacheTodo(c appengine.Context, todoKey string, todo *Todo) { func cacheTodo(c appengine.Context, todoKey string, todo *Todo) {
// Get the todo cache record (or create a new one). // Get the todo cache record (or create a new one).
newItem := false newItem := false
t, miss := todoCache(c) t := todoCache(c)
if miss { if t == nil {
newItem = true newItem = true
t = &memcache.Item{ t = &memcache.Item{
Key: todoCacheKey, Key: todoCacheKey,
Value: []byte("{}"), // default is an empty JSON object Value: []byte("{}"), // default is an empty JSON object
} }
} }
if t == nil {
return
}
// Unmarshal the JSON value. // Unmarshal the JSON value.
todos := unmarshalTodo(c, t) todos := unmarshalTodo(c, t)
...@@ -98,15 +95,15 @@ func cacheTodo(c appengine.Context, todoKey string, todo *Todo) { ...@@ -98,15 +95,15 @@ func cacheTodo(c appengine.Context, todoKey string, todo *Todo) {
} }
// todoCache gets the todo cache record from memcache (if it exists). // 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) t, err := memcache.Get(c, todoCacheKey)
if err == memcache.ErrCacheMiss { if err != nil {
return nil, true if err != memcache.ErrCacheMiss {
} else if err != nil {
c.Errorf("get todo cache: %v", err) c.Errorf("get todo cache: %v", err)
return nil, false
} }
return t, false return nil
}
return t
} }
// unmarshalTodo decodes the given item's memcache value into a map. // unmarshalTodo decodes the given item's memcache value into a map.
......
...@@ -150,7 +150,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) { ...@@ -150,7 +150,7 @@ func todoHandler(r *http.Request) (interface{}, os.Error) {
c := appengine.NewContext(r) c := appengine.NewContext(r)
todoKey := r.Form.Encode() todoKey := r.Form.Encode()
if t, hit := cachedTodo(c, todoKey); hit { if t, ok := cachedTodo(c, todoKey); ok {
c.Debugf("cache hit") c.Debugf("cache hit")
return t, nil return t, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment