
org.codehaus.plexus.cache.oscache.OsCacheCreator Maven / Gradle / Ivy
The newest version!
package org.codehaus.plexus.cache.oscache;
/*
* Copyright 2001-2007 The Codehaus.
*
* Licensed 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.
*/
import org.apache.commons.lang.SystemUtils;
import org.codehaus.plexus.cache.Cache;
import org.codehaus.plexus.cache.CacheException;
import org.codehaus.plexus.cache.CacheHints;
import org.codehaus.plexus.cache.factory.CacheCreator;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
import java.io.File;
/**
* OsCacheCreator
*
* @author Joakim Erdfelt
* @version $Id: OsCacheCreator.java 5945 2007-02-27 01:33:18Z joakime $
*/
public class OsCacheCreator
implements CacheCreator
{
public Cache createCache( CacheHints hints )
throws CacheException
{
OsCacheCache cache = new OsCacheCache();
cache.setCacheKey( hints.getName() );
cache.setCachePersistenceOverflowOnly( hints.isOverflowToDisk() );
if ( hints.isOverflowToDisk() )
{
File overflowPath = null;
if ( hints.getDiskOverflowPath() != null )
{
overflowPath = hints.getDiskOverflowPath();
}
else
{
File tmpDir = SystemUtils.getJavaIoTmpDir();
overflowPath = new File( tmpDir, "oscache/" + hints.getName() );
}
cache.setCachePath( overflowPath.getAbsolutePath() );
}
cache.setCapacity( hints.getMaxElements() );
cache.setRefreshPeriod( hints.getIdleExpirationSeconds() );
// Does not support: hints.getMaxSecondsInCache()
try
{
cache.initialize();
}
catch ( InitializationException e )
{
throw new CacheException( "Unable to initialize OsCacheCache: " + e.getMessage(), e );
}
return cache;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy