5 // Copy&paste this for new cache types
6 // globally replace: Strut strut SID sid
17 func (v *Strut) touch() {
20 func (v *Strut) isStale(d time.Duration) bool {
21 return time.Now().Sub(v.Cached) > d
26 func (sid SID) Strut() *Strut {
27 return strutCache.Get(sid)
30 var StrutCacheDuration = DefaultCacheDuration
32 var strutCache = strutCacheStruct{baseCache: newBaseCache()}
34 type strutCacheStruct struct{ baseCache }
36 func (c *strutCacheStruct) Get(id SID) *Strut {
37 return c.baseCache.Get(int(id)).(*Strut)
40 func (c *strutCacheStruct) Set(id SID, v *Strut) {
41 c.baseCache.Set(int(id), v)
44 func (c *strutCacheStruct) Intent(id SID, ch chan *Strut) (ok bool) {
45 ch2 := make(chan cacheable, 1)
46 go func() { ch <- (<-ch2).(*Strut) }()
47 return c.baseCache.Intent(int(id), ch2)
50 func (adb *AniDB) StrutBySID(id SID) <-chan *Strut {
51 ch := make(chan *Strut, 1)
52 if v := id.Strut(); !v.isStale(StrutCacheDuration) {
58 if strutCache.Intent(id, ch) {