Cache
Mutable, fixed-capacity cache whose eviction strategy depends on the specific implementation.
A Cache is useful whenever some expensive computation (e.g. an MGU computation, a number-format conversion, a parsed representation) is repeatedly requested for the same input, and memory usage must be bounded: unlike a plain MutableMap, a Cache never grows past capacity, evicting older entries (following the policy of the concrete implementation) as new ones are stored. Instances are created via the factory methods in the companion object, e.g. Cache.lru or Cache.simpleLru.
For instance, it.unibo.tuprolog.unify.CachedUnificator (in the :unify module) uses a Cache to memoize the results of most general unifier computations:
private val mguCache: Cache<MguRequest, Substitution> = Cache.simpleLru(cacheCapacity)Type Parameters
is the type of the keys used for indexing items in this cache
is the type of the values stored in this cache