aboutsummaryrefslogtreecommitdiff
path: root/cache/cache.go
diff options
context:
space:
mode:
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
}