-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcache.go
More file actions
44 lines (35 loc) · 779 Bytes
/
cache.go
File metadata and controls
44 lines (35 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package yarf
import (
"sync"
)
// RouteCache stores previously matched and parsed routes
type RouteCache struct {
route []Router
params Params
}
// Cache is the service handler for route caching
type Cache struct {
// Cache data storage
storage map[string]RouteCache
// Sync Mutex
sync.RWMutex
}
// NewCache creates and initializes a new Cache service object.
func NewCache() *Cache {
return &Cache{
storage: make(map[string]RouteCache),
}
}
// Get retrieves a routeCache object by key name.
func (c *Cache) Get(k string) (rc RouteCache, ok bool) {
c.RLock()
defer c.RUnlock()
rc, ok = c.storage[k]
return
}
// Set stores a routeCache object under a key name.
func (c *Cache) Set(k string, r RouteCache) {
c.Lock()
defer c.Unlock()
c.storage[k] = r
}