| 120 | } |
| 121 | |
| 122 | func TestMemoryList_Stat(t *testing.T) { |
| 123 | list := caches.NewMemoryList() |
| 124 | _ = list.Init() |
| 125 | _ = list.Add("a", &caches.Item{ |
| 126 | Key: "a1", |
| 127 | ExpiresAt: time.Now().Unix() + 3600, |
| 128 | HeaderSize: 1024, |
| 129 | }) |
| 130 | _ = list.Add("b", &caches.Item{ |
| 131 | Key: "b1", |
| 132 | ExpiresAt: time.Now().Unix() + 3600, |
| 133 | HeaderSize: 1024, |
| 134 | }) |
| 135 | _ = list.Add("c", &caches.Item{ |
| 136 | Key: "c1", |
| 137 | ExpiresAt: time.Now().Unix(), |
| 138 | HeaderSize: 1024, |
| 139 | }) |
| 140 | _ = list.Add("d", &caches.Item{ |
| 141 | Key: "d1", |
| 142 | ExpiresAt: time.Now().Unix() - 2, |
| 143 | HeaderSize: 1024, |
| 144 | }) |
| 145 | result, _ := list.Stat(func(hash string) bool { |
| 146 | // 随机测试 |
| 147 | return rand.Int()%2 == 0 |
| 148 | }) |
| 149 | t.Log(result) |
| 150 | } |
| 151 | |
| 152 | func TestMemoryList_CleanPrefix(t *testing.T) { |
| 153 | list := caches.NewMemoryList() |