All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yahoo.elide.security.permissions.ExpressionResultCache Maven / Gradle / Ivy

There is a newer version: 7.1.4
Show newest version
/*
 * 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 checkClass, PersistentResource resource) {
        return computedResults.containsKey(checkClass)
                && computedResults.get(checkClass).containsKey(resource);
    }

    public void putResultFor(Class 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 checkClass, PersistentResource resource) {
        return computedResults.get(checkClass).get(resource);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy