diff options
| author | jackyzha0 <[email protected]> | 2020-05-09 15:51:00 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-09 15:51:00 -0700 |
| commit | af0031eadbfe88fe8125c0add97d71f1c7fcc801 (patch) | |
| tree | 4ff9693cecd149ad91d6f0465746104a22378c08 /cache | |
| parent | fix dockerfile envs (diff) | |
| download | ctrl-v-af0031eadbfe88fe8125c0add97d71f1c7fcc801.tar.xz ctrl-v-af0031eadbfe88fe8125c0add97d71f1c7fcc801.zip | |
fix port bug
Diffstat (limited to 'cache')
| -rw-r--r-- | cache/cache.go | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/cache/cache.go b/cache/cache.go index da27939..b311efa 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -19,10 +19,12 @@ func New() *Cache { func (c *Cache) Get(hash string) (db.Paste, error) { c.lock.RLock() - defer c.lock.RUnlock() // check if hash in cache - if v, ok := c.m[hash]; ok { + v, ok := c.m[hash] + c.lock.RUnlock() + + if ok { return v, nil } @@ -34,6 +36,7 @@ func (c *Cache) Get(hash string) (db.Paste, error) { func (c *Cache) add(p db.Paste) { c.lock.Lock() + defer c.lock.Unlock() + c.m[p.Hash] = p - c.lock.Unlock() } |