aboutsummaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
committerjackyzha0 <[email protected]>2020-05-09 20:15:59 -0700
commitdedabf41a18820527aed9e77b75564e69c9030ce (patch)
tree9258832576f9c1bcad6126cf76ef8f7f6a128e82 /cache
parentMerge pull request #3 from jackyzha0/doc-expiry (diff)
downloadctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.tar.xz
ctrl-v-dedabf41a18820527aed9e77b75564e69c9030ce.zip
folder refactor
Diffstat (limited to 'cache')
-rw-r--r--cache/cache.go44
1 files changed, 0 insertions, 44 deletions
diff --git a/cache/cache.go b/cache/cache.go
deleted file mode 100644
index bac7ea8..0000000
--- a/cache/cache.go
+++ /dev/null
@@ -1,44 +0,0 @@
-package cache
-
-import (
- "sync"
-
- "github.com/jackyzha0/ctrl-v/db"
-)
-
-type Cache struct {
- m map[string]db.Paste
- lock sync.RWMutex
-}
-
-var C *Cache
-
-func init() {
- C = &Cache{
- m: map[string]db.Paste{},
- }
-}
-
-func (c *Cache) Get(hash string) (db.Paste, error) {
- c.lock.RLock()
-
- // check if hash in cache
- v, ok := c.m[hash]
- c.lock.RUnlock()
-
- if ok {
- return v, nil
- }
-
- // if it doesnt, lookup from db
- p, err := db.Lookup(hash)
- c.add(p)
- return p, err
-}
-
-func (c *Cache) add(p db.Paste) {
- c.lock.Lock()
- defer c.lock.Unlock()
-
- c.m[p.Hash] = p
-}