diff --git a/gee-cache/day1-lru/geecache/lru/lru.go b/gee-cache/day1-lru/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day1-lru/geecache/lru/lru.go +++ b/gee-cache/day1-lru/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day2-single-node/geecache/lru/lru.go b/gee-cache/day2-single-node/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day2-single-node/geecache/lru/lru.go +++ b/gee-cache/day2-single-node/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day3-http-server/geecache/lru/lru.go b/gee-cache/day3-http-server/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day3-http-server/geecache/lru/lru.go +++ b/gee-cache/day3-http-server/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day4-consistent-hash/geecache/lru/lru.go b/gee-cache/day4-consistent-hash/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day4-consistent-hash/geecache/lru/lru.go +++ b/gee-cache/day4-consistent-hash/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day5-multi-nodes/geecache/lru/lru.go b/gee-cache/day5-multi-nodes/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day5-multi-nodes/geecache/lru/lru.go +++ b/gee-cache/day5-multi-nodes/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day6-single-flight/geecache/lru/lru.go b/gee-cache/day6-single-flight/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day6-single-flight/geecache/lru/lru.go +++ b/gee-cache/day6-single-flight/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/day7-proto-buf/geecache/lru/lru.go b/gee-cache/day7-proto-buf/geecache/lru/lru.go index 6fa617a..dc1a317 100644 --- a/gee-cache/day7-proto-buf/geecache/lru/lru.go +++ b/gee-cache/day7-proto-buf/geecache/lru/lru.go @@ -39,12 +39,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-cache/doc/geecache-day1.md b/gee-cache/doc/geecache-day1.md index 064d90a..2f096d9 100644 --- a/gee-cache/doc/geecache-day1.md +++ b/gee-cache/doc/geecache-day1.md @@ -155,12 +155,11 @@ func (c *Cache) Add(key string, value Value) { kv := ele.Value.(*entry) c.nbytes += int64(value.Len()) - int64(kv.value.Len()) kv.value = value - return + } else { + ele := c.ll.PushFront(&entry{key, value}) + c.cache[key] = ele + c.nbytes += int64(len(key)) + int64(value.Len()) } - ele := c.ll.PushFront(&entry{key, value}) - c.cache[key] = ele - c.nbytes += int64(len(key)) + int64(value.Len()) - for c.maxBytes != 0 && c.maxBytes < c.nbytes { c.RemoveOldest() } diff --git a/gee-orm/day7-migrate/geeorm.go b/gee-orm/day7-migrate/geeorm.go index 017d116..f9bbcd8 100644 --- a/gee-orm/day7-migrate/geeorm.go +++ b/gee-orm/day7-migrate/geeorm.go @@ -106,7 +106,7 @@ func (engine *Engine) Migrate(value interface{}) error { for _, col := range addCols { f := table.GetField(col) - sqlStr := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s;", table.Name, f.Name, f.Tag) + sqlStr := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s;", table.Name, f.Name, f.Type) if _, err = s.Raw(sqlStr).Exec(); err != nil { return } diff --git a/gee-orm/doc/geeorm-day7.md b/gee-orm/doc/geeorm-day7.md index 44079fd..7e6dc1c 100644 --- a/gee-orm/doc/geeorm-day7.md +++ b/gee-orm/doc/geeorm-day7.md @@ -89,7 +89,7 @@ func (engine *Engine) Migrate(value interface{}) error { for _, col := range addCols { f := table.GetField(col) - sqlStr := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s;", table.Name, f.Name, f.Tag) + sqlStr := fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s;", table.Name, f.Name, f.Type) if _, err = s.Raw(sqlStr).Exec(); err != nil { return } diff --git a/gee-web/doc/gee-day3.md b/gee-web/doc/gee-day3.md index 4b34f6d..0d66e54 100644 --- a/gee-web/doc/gee-day3.md +++ b/gee-web/doc/gee-day3.md @@ -18,7 +18,7 @@ github: https://github.com/geektutu/7days-golang 本文是 [7天用Go从零实现Web框架Gee教程系列](https://geektutu.com/post/gee.html)的第三篇。 -- 使用 Tire 树实现动态路由(dynamic route)解析。 +- 使用 Trie 树实现动态路由(dynamic route)解析。 - 支持两种模式`:name`和`*filepath`,**代码约150行**。 ## Trie 树简介