()
| 28 | } |
| 29 | |
| 30 | func (c *MemoryCache) setTtlTimer() { |
| 31 | for { |
| 32 | c.Lock() |
| 33 | for k, v := range c.cache { |
| 34 | if time.Now().Unix()-v.createdAt > v.ttl { |
| 35 | delete(c.cache, k) |
| 36 | } |
| 37 | } |
| 38 | c.Unlock() |
| 39 | |
| 40 | <-time.After(time.Second) |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | func (c *MemoryCache) Set(key, value interface{}, ttl int64) error { |
| 45 | c.Lock() |