-
Notifications
You must be signed in to change notification settings - Fork 110
/
cache.go
34 lines (26 loc) · 912 Bytes
/
cache.go
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
package jet
import "sync"
// Cache is the interface Jet uses to store and retrieve parsed templates.
type Cache interface {
// Get fetches a template from the cache. If Get returns nil, the same path with a different extension will be tried.
// If Get() returns nil for all configured extensions, the same path and extensions will be tried on the Set's Loader.
Get(templatePath string) *Template
// Put places the result of parsing a template "file"/string in the cache.
Put(templatePath string, t *Template)
}
// cache is the cache used by default in a new Set.
type cache struct {
m sync.Map
}
// compile-time check that cache implements Cache
var _ Cache = (*cache)(nil)
func (c *cache) Get(templatePath string) *Template {
_t, ok := c.m.Load(templatePath)
if !ok {
return nil
}
return _t.(*Template)
}
func (c *cache) Put(templatePath string, t *Template) {
c.m.Store(templatePath, t)
}