/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.jena.riot.adapters;

import java.util.HashMap ;
import java.util.Map ;

import com.hp.hpl.jena.rdf.model.Model ;

// Legacy support.
class FileManagerModelCache {
    
    public FileManagerModelCache() {}
    
    boolean cacheModelLoads = false ;
    Map<String, Model> modelCache = null ;
    // -------- Cache operations
    
    /** Reset the model cache */
    public void resetCache()
    {
        if ( modelCache != null )
            modelCache.clear() ;
    }
    
    /** Change the state of model cache : does not clear the cache */ 
    public void setModelCaching(boolean state)
    {
        cacheModelLoads = state ;
        if ( cacheModelLoads && modelCache == null )
            modelCache = new HashMap<String, Model>() ;
    }
    
    /** return whether caching is on of off */
    public boolean isCachingModels() { return cacheModelLoads ; }
    
    /** Read out of the cache - return null if not in the cache */ 
    public Model getFromCache(String filenameOrURI)
    { 
        if ( ! isCachingModels() )
            return null; 
        return modelCache.get(filenameOrURI) ;
    }
    
    public boolean hasCachedModel(String filenameOrURI)
    { 
        if ( ! isCachingModels() )
            return false ; 
        return modelCache.containsKey(filenameOrURI) ;
    }
    
    public void addCacheModel(String uri, Model m)
    { 
        if ( isCachingModels() )
            modelCache.put(uri, m) ;
    }

    public void removeCacheModel(String uri)
    { 
        if ( isCachingModels() )
            modelCache.remove(uri) ;
    }


}

@@ -852,48 +852,87 @@
 ort 
-java.util.HashMap ;%0Aimport java.util.Map
+org.apache.jena.atlas.lib.Cache ;%0Aimport org.apache.jena.atlas.lib.CacheFactory
  ;%0A%0A
@@ -1022,20 +1022,64 @@
 Cache %7B%0A
+%0A
     
+private static final int CacheSize = 500 ; 
 %0A    pub
@@ -1156,19 +1156,21 @@
 e ;%0A    
-Map
+Cache
 %3CString,
@@ -1621,35 +1621,42 @@
 e = 
-new HashMap%3CString, Model%3E(
+CacheFactory.createCache(CacheSize
 ) ;%0A

Switch to an LRU cache for models (when cache enabled)