Improved Caching Performance
Improvements
- A
WeakMap
is now instead of aMap
to cacheEnumWrapper
instances. This ensures thatEnumWrapper
instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks). This should also improve cache set/get performance becauseWeakMap
implementations can feature O(1) constant time set/get. - The
$enum()
function was also optimized by making it a direct alias/reference toEnumWrapper.getCachedInstance()
.
Breaking Changes
Because WeakMap
solves the concern about memory leaks when ts-enum-util
is used on temporary enum-like objects, there's really no need to opt out of caching any more. Accordingly, the following API changes were made:
- Removed
EnumWrapper.createUncachedInstance()
- Removed optional
useCache
param to the$enum()
function (it now always uses the cache).