aboutsummaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorJacky Zhao <[email protected]>2020-05-09 15:51:43 -0700
committerGitHub <[email protected]>2020-05-09 15:51:43 -0700
commitb88fa4abe6d458394716e278a3ee8e8859a973fb (patch)
treebd9c1f6034787e081b6097a2e24747902b552f3b /cache
parentAdd get hash endpoint (diff)
parentfix port bug (diff)
downloadctrl-v-b88fa4abe6d458394716e278a3ee8e8859a973fb.tar.xz
ctrl-v-b88fa4abe6d458394716e278a3ee8e8859a973fb.zip
Merge branch 'master' into api
Diffstat (limited to 'cache')
-rw-r--r--cache/cache.go4
1 files changed, 3 insertions, 1 deletions
diff --git a/cache/cache.go b/cache/cache.go
index a8c4244..bac7ea8 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -25,6 +25,7 @@ func (c *Cache) Get(hash string) (db.Paste, error) {
// check if hash in cache
v, ok := c.m[hash]
c.lock.RUnlock()
+
if ok {
return v, nil
}
@@ -37,6 +38,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()
}