()
| 3 | import "time" |
| 4 | |
| 5 | func (c *Cache[KeyType, DataType]) LifeCycle() { |
| 6 | c.Mutex.Lock() |
| 7 | defer c.Mutex.Unlock() |
| 8 | unixtime := time.Now().Unix() |
| 9 | for key, item := range c.Items { |
| 10 | if item.LifeTime == 0 { |
| 11 | continue |
| 12 | } |
| 13 | if item.LifeTime < unixtime { |
| 14 | if c.Properties.TimeoutCacheEvent { |
| 15 | c.TimeoutCacheEvent <- CacheEvent[KeyType, DataType]{ |
| 16 | Key: key, |
| 17 | Data: item.Data, |
| 18 | } |
| 19 | } |
| 20 | delete(c.Items, key) |
| 21 | } |
| 22 | } |
| 23 | } |