SoftKeyArrayMap
A pure-Kotlin common WeakMap implementation using SoftRef.
Keys are compared using equals.
This implementation is ideal when caching requests that are relatively expensive or when the same keys are requested throughout the app's lifetime: we prefer to keep the cached value longer as long as there is memory available.
Performance characteristics
Elements are stored in an ArrayList. On each operation, elements are scanned linearly until the element on which the operation is requested is found. Expired elements are freed when they are visited. This implies that all operations are in O(n)
.
Additionally, older elements are visited more often, so they are more likely to be freed early.