Lazy class has a
.clear() method. When called, the reference held in the Lazy Reference is removed and only the ID is kept so that the instance can be reloaded when needed.
So that the Lazy References do not have to be managed manually, but the whole goes automatically, there is the following mechanism: Each
Lazy instance has a
lastTouched timestamp. Each
.get() call sets it to the current time. This will tell you how long a Lazy Reference has not been used, i.e. if it is needed at all.
LazyReferenceManager audits this. By default, it is not enabled because it needs its own thread and it's problematic when frameworks start threads unsolicited. But it is activated quickly:
// Lazy References timeout after 10 minutes without accessLazyReferenceManager.set(LazyReferenceManager.New(Duration.ofMinutes(10).toMillis()).start());