下面列出了com.google.common.cache.CacheBuilderSpec#parse ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void run(AssetsBundleConfiguration bundleConfig, Environment env) throws Exception {
AssetsConfiguration config = bundleConfig.getAssetsConfiguration();
// Let the cache spec from the configuration override the one specified in the code
CacheBuilderSpec spec = (config.getCacheSpec() != null)
? CacheBuilderSpec.parse(config.getCacheSpec())
: cacheBuilderSpec;
Iterable<Map.Entry<String, String>> overrides = config.getOverrides().entrySet();
Iterable<Map.Entry<String, String>> mimeTypes = config.getMimeTypes().entrySet();
Iterable<Map.Entry<String, String>> servletResourcePathToUriMappings;
if (!config.getResourcePathToUriMappings().isEmpty()) {
servletResourcePathToUriMappings = config.getResourcePathToUriMappings().entrySet();
} else {
servletResourcePathToUriMappings = resourcePathToUriMappings;
}
AssetServlet servlet = new AssetServlet(servletResourcePathToUriMappings, indexFile,
Charsets.UTF_8, spec, overrides, mimeTypes);
for (Map.Entry<String, String> mapping : servletResourcePathToUriMappings) {
String mappingPath = mapping.getValue();
if (!mappingPath.endsWith("/")) {
mappingPath += '/';
}
mappingPath += "*";
servlet.setCacheControlHeader(config.getCacheControlHeader());
LOGGER.info("Registering ConfiguredAssetBundle with name: {} for path {}", assetsName,
mappingPath);
env.servlets().addServlet(assetsName, servlet).addMapping(mappingPath);
}
}
@Override
public CacheBuilderSpec convert(String spec) throws OptionsParsingException {
try {
return Strings.isNullOrEmpty(spec) ? null : CacheBuilderSpec.parse(spec);
} catch (IllegalArgumentException e) {
throw new OptionsParsingException("Failed to parse CacheBuilderSpec: " + e.getMessage(), e);
}
}
@JsonProperty
public void setQueryCache(String queryCache) {
this.queryCache = CacheBuilderSpec.parse(queryCache);
}
public GuavaCacheManager(CacheRegistry cacheRegistry, String cacheBuilderSpec) {
_spec = CacheBuilderSpec.parse(checkNotNull(cacheBuilderSpec));
_cacheRegistry = cacheRegistry;
}
private Authenticator<BasicCredentials, User> cache(Authenticator<BasicCredentials, User> authenticator) {
return new CachingAuthenticator<>(environment.metrics(), authenticator, CacheBuilderSpec.parse(authConfig.getCachePolicy()));
}
@Before
public void setUp() throws Exception {
when(underlying.authenticate(anyString())).thenReturn(Optional.<Principal>of(new PrincipalImpl("principal")));
cached = new CachingAuthenticator<>(new MetricRegistry(), underlying, CacheBuilderSpec.parse("maximumSize=1"));
}