Forcing deallocation of large cache object in Java

后端 未结 7 1009
醉梦人生
醉梦人生 2021-02-04 09:36

I use a large (millions) entries hashmap to cache values needed by an algorithm, the key is a combination of two objects as a long. Since it grows continuously (because keys in

7条回答
  •  无人共我
    2021-02-04 10:29

    If you have a bit of spare memory you could implement a timout cache where each value in the hashmap contains your long value and an insersion timestamp in millis - then have a background thread iterate over the values every X seconds and remove anything more than X seconds/millis old.

    Just my 2 cents :)

提交回复
热议问题