Search in sources :

Example 1 with VirAttrCacheKey

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);
    }
}
Also used : VirAttrCacheValue(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue) VirAttrCacheKey(org.apache.syncope.core.provisioning.api.cache.VirAttrCacheKey) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date) HashSet(java.util.HashSet)

Aggregations

Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 VirAttrCacheKey (org.apache.syncope.core.provisioning.api.cache.VirAttrCacheKey)1 VirAttrCacheValue (org.apache.syncope.core.provisioning.api.cache.VirAttrCacheValue)1