aboutsummaryrefslogtreecommitdiff
path: root/cache/cache.go
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-09 16:50:38 -0600
committerRyan Mehri <[email protected]>2020-05-09 16:50:38 -0600
commitb80d38e7a5173fd2126ab01b8412fa871cb43dca (patch)
tree1ccd0aeb4a49e5878ce2ea1496e09ab9440c9500 /cache/cache.go
parentadd dockerfile and makefile (diff)
downloadctrl-v-b80d38e7a5173fd2126ab01b8412fa871cb43dca.tar.xz
ctrl-v-b80d38e7a5173fd2126ab01b8412fa871cb43dca.zip
Add get hash endpoint
Diffstat (limited to 'cache/cache.go')
-rw-r--r--cache/cache.go11
1 files changed, 7 insertions, 4 deletions
diff --git a/cache/cache.go b/cache/cache.go
index da27939..a8c4244 100644
--- a/cache/cache.go
+++ b/cache/cache.go
@@ -11,18 +11,21 @@ type Cache struct {
lock sync.RWMutex
}
-func New() *Cache {
- return &Cache{
+var C *Cache
+
+func init() {
+ C = &Cache{
m: map[string]db.Paste{},
}
}
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
}