aboutsummaryrefslogtreecommitdiff
path: root/cache/cache.go
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 15:51:00 -0700
committerjackyzha0 <[email protected]>2020-05-09 15:51:00 -0700
commitaf0031eadbfe88fe8125c0add97d71f1c7fcc801 (patch)
tree4ff9693cecd149ad91d6f0465746104a22378c08 /cache/cache.go
parentfix dockerfile envs (diff)
downloadctrl-v-af0031eadbfe88fe8125c0add97d71f1c7fcc801.tar.xz
ctrl-v-af0031eadbfe88fe8125c0add97d71f1c7fcc801.zip
fix port bug
Diffstat (limited to 'cache/cache.go')
-rw-r--r--cache/cache.go9
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()
}