com.yahoo.elide.security.permissions.ExpressionResultCache Maven / Gradle / Ivy
/*
* Copyright 2016, Yahoo Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE file in project root for terms.
*/
package com.yahoo.elide.security.permissions;
import com.yahoo.elide.security.PersistentResource;
import com.yahoo.elide.security.checks.Check;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.Map;
/**
* Used to cache the results of checks so that if a check is not evaluated more than once for a given resource.
*/
public class ExpressionResultCache {
private final Map, Map> computedResults;
public ExpressionResultCache() {
computedResults = new HashMap<>();
}
public boolean hasStoredResultFor(Class extends Check> checkClass, PersistentResource resource) {
return computedResults.containsKey(checkClass)
&& computedResults.get(checkClass).containsKey(resource);
}
public void putResultFor(Class extends Check> checkClass, PersistentResource resource, ExpressionResult result) {
Map cache = computedResults.get(checkClass);
if (cache == null) {
cache = new IdentityHashMap<>();
computedResults.put(checkClass, cache);
}
cache.put(resource, result);
}
public ExpressionResult getResultFor(Class extends Check> checkClass, PersistentResource resource) {
return computedResults.get(checkClass).get(resource);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy