use of org.apache.syncope.core.provisioning.api.cache.VirAttrCacheKey in project syncope by apache.
the class MemoryVirAttrCache method free.
/**
* Remove expired entries if exist. If required, one entry at least (the latest recently used) will be taken off.
* This method is not thread safe: the caller have to take care to synchronize the call.
*/
private void free() {
final Set<VirAttrCacheKey> toBeRemoved = new HashSet<>();
Map.Entry<VirAttrCacheKey, VirAttrCacheValue> latest = null;
for (Map.Entry<VirAttrCacheKey, VirAttrCacheValue> entry : cache.entrySet()) {
if (isValidEntry(entry.getValue())) {
final Date date = entry.getValue().getLastAccessDate();
if (latest == null || latest.getValue().getLastAccessDate().after(date)) {
latest = entry;
}
} else {
toBeRemoved.add(entry.getKey());
}
}
if (toBeRemoved.isEmpty() && latest != null) {
// remove the oldest entry
cache.remove(latest.getKey());
} else {
// remove expired entries
cache.keySet().removeAll(toBeRemoved);
}
}
Aggregations