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

com.jayway.jsonpath.spi.cache.CacheProvider Maven / Gradle / Ivy

There is a newer version: 4.15.0-HBase-1.5
Show newest version
package com.jayway.jsonpath.spi.cache;

import com.jayway.jsonpath.JsonPathException;

import static com.jayway.jsonpath.internal.Utils.notNull;

public class CacheProvider {
    private static Cache cache;
    private static boolean cachingEnabled;

    public static void setCache(Cache cache){
        notNull(cache, "Cache may not be null");
        synchronized (CacheProvider.class){
            if(CacheProvider.cache != null){
                throw new JsonPathException("Cache provider must be configured before cache is accessed.");
            } else {
                CacheProvider.cache = cache;
            }
            cachingEnabled = !(CacheProvider.cache instanceof NOOPCache);
        }
    }

    public static Cache getCache() {
        if(CacheProvider.cache == null){
            synchronized (CacheProvider.class){
                if(CacheProvider.cache == null){
                    CacheProvider.cache = getDefaultCache();
                }
            }
        }
        return CacheProvider.cache;
    }


    private static Cache getDefaultCache(){
        return new LRUCache(400);
        //return new NOOPCache();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy