View Javadoc
1   package org.kuali.common.devops.cache;
2   
3   import static org.kuali.common.devops.cache.UrlLoader.newUrlLoader;
4   import static org.kuali.common.devops.cache.UrlPropertiesFileFunction.newUrlPropertiesFileFunction;
5   import static org.kuali.common.http.model.HttpContext.newHttpContext;
6   
7   import java.io.File;
8   
9   import org.kuali.common.http.model.HttpContext;
10  import org.kuali.common.http.model.HttpWaitResult;
11  
12  import com.google.common.base.Function;
13  import com.google.common.cache.CacheLoader;
14  
15  public class Caches {
16  
17  	public static <T, V> FileSystemCache<String, HttpWaitResult> buildUrlCache() {
18  		return buildUrlCache(newHttpContext());
19  	}
20  
21  	public static <T, V> FileSystemCache<String, HttpWaitResult> buildUrlCache(HttpContext context) {
22  		return buildUrlCache(context, newUrlPropertiesFileFunction().getBasedir(), context.getEncoding());
23  	}
24  
25  	public static <T, V> FileSystemCache<String, HttpWaitResult> buildUrlCache(HttpContext context, File basedir) {
26  		return buildUrlCache(context, basedir, context.getEncoding());
27  	}
28  
29  	public static <T, V> FileSystemCache<String, HttpWaitResult> buildUrlCache(HttpContext context, File basedir, String encoding) {
30  		CacheLoader<String, HttpWaitResult> loader = newUrlLoader(context);
31  		PersistentCache<File, HttpWaitResult> fileCache = new UrlFileCache();
32  		Function<String, File> keyConverter = newUrlPropertiesFileFunction(basedir);
33  
34  		FileSystemCache.Builder<String, HttpWaitResult> builder = FileSystemCache.builder();
35  		builder.keyConverter(keyConverter);
36  		builder.loader(loader);
37  		builder.fileCache(fileCache);
38  		builder.ignoreFileSystem(Boolean.getBoolean("cache.ignoreFileSystem"));
39  		return builder.build();
40  	}
41  
42  }