If exisitng records are rarely (or never) updated, so frequent updates are often frequent additions, you can use temporary ordering to optimize the data structure by separating old and new elements.
For example, you can segment the cache into several CopyOnWriteArrayList objects, each of which contains no more than a fixed number of elements, and each segment contains a temporary data sub-range. Frequent additions would increase the last segment to the maximum size, after which you would add a new segment for future updates. CopyOnWriteArrayList maximum segment size, you should avoid CopyOnWriteArrayList performance CopyOnWriteArrayList . You must hide implementation details in your own List class.
Edit: Deleting old elements similarly changes only one segment: the oldest segment.
source share