本文整理匯總了Java中com.google.common.cache.LoadingCache類的典型用法代碼示例。如果您正苦於以下問題:Java LoadingCache類的具體用法?Java LoadingCache怎麽用?Java LoadingCache使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LoadingCache類屬於com.google.common.cache包,在下文中一共展示了LoadingCache類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createFilesCache
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
private LoadingCache<Integer, Bucket> createFilesCache(final MinebdConfig config) {
Preconditions.checkNotNull(config.parentDirs);
final Integer maxOpenFiles = config.maxOpenFiles;
Preconditions.checkNotNull(maxOpenFiles);
Preconditions.checkArgument(maxOpenFiles > 0);
return CacheBuilder.newBuilder()
.maximumSize(maxOpenFiles)
.removalListener((RemovalListener<Integer, Bucket>) notification -> {
logger.debug("no longer monitoring bucket {}", notification.getKey());
try {
notification.getValue().close();
} catch (IOException e) {
logger.warn("unable to flush and close file " + notification.getKey(), e);
}
})
.build(new CacheLoader<Integer, Bucket>() {
@Override
public Bucket load(Integer key) throws Exception {
return bucketFactory.create(key);
}
});
}
示例2: casEventRepository
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Bean
public CasEventRepository casEventRepository() {
final LoadingCache<String, CasEvent> storage = CacheBuilder.newBuilder()
.initialCapacity(INITIAL_CACHE_SIZE)
.maximumSize(MAX_CACHE_SIZE)
.recordStats()
.expireAfterWrite(EXPIRATION_TIME, TimeUnit.HOURS)
.build(new CacheLoader<String, CasEvent>() {
@Override
public CasEvent load(final String s) throws Exception {
LOGGER.error("Load operation of the cache is not supported.");
return null;
}
});
LOGGER.debug("Created an in-memory event repository to store CAS events for [{}] hours", EXPIRATION_TIME);
return new InMemoryCasEventRepository(storage);
}
示例3: mfaTrustEngine
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@ConditionalOnMissingBean(name = "mfaTrustEngine")
@Bean
@RefreshScope
public MultifactorAuthenticationTrustStorage mfaTrustEngine() {
final LoadingCache<String, MultifactorAuthenticationTrustRecord> storage = CacheBuilder.newBuilder()
.initialCapacity(INITIAL_CACHE_SIZE)
.maximumSize(MAX_CACHE_SIZE)
.recordStats()
.expireAfterWrite(casProperties.getAuthn().getMfa().getTrusted().getExpiration(),
casProperties.getAuthn().getMfa().getTrusted().getTimeUnit())
.build(new CacheLoader<String, MultifactorAuthenticationTrustRecord>() {
@Override
public MultifactorAuthenticationTrustRecord load(final String s) throws Exception {
LOGGER.error("Load operation of the cache is not supported.");
return null;
}
});
final InMemoryMultifactorAuthenticationTrustStorage m = new InMemoryMultifactorAuthenticationTrustStorage(storage);
m.setCipherExecutor(mfaTrustCipherExecutor());
return m;
}
示例4: checkPatternAt
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
/**
* checks that the given pattern & rotation is at the block co-ordinates.
*/
@Nullable
private BlockPattern.PatternHelper checkPatternAt(BlockPos pos, EnumFacing finger, EnumFacing thumb, LoadingCache<BlockPos, BlockWorldState> lcache)
{
for (int i = 0; i < this.palmLength; ++i)
{
for (int j = 0; j < this.thumbLength; ++j)
{
for (int k = 0; k < this.fingerLength; ++k)
{
if (!this.blockMatches[k][j][i].apply(lcache.getUnchecked(translateOffset(pos, finger, thumb, i, j, k))))
{
return null;
}
}
}
}
return new BlockPattern.PatternHelper(pos, finger, thumb, lcache, this.palmLength, this.thumbLength, this.fingerLength);
}
示例5: checkPatternAt
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
/**
* checks that the given pattern & rotation is at the block co-ordinates.
*/
private BlockPattern.PatternHelper checkPatternAt(BlockPos pos, EnumFacing finger, EnumFacing thumb, LoadingCache<BlockPos, BlockWorldState> lcache)
{
for (int i = 0; i < this.palmLength; ++i)
{
for (int j = 0; j < this.thumbLength; ++j)
{
for (int k = 0; k < this.fingerLength; ++k)
{
if (!this.blockMatches[k][j][i].apply(lcache.getUnchecked(translateOffset(pos, finger, thumb, i, j, k))))
{
return null;
}
}
}
}
return new BlockPattern.PatternHelper(pos, finger, thumb, lcache, this.palmLength, this.thumbLength, this.fingerLength);
}
示例6: get
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Override
public synchronized Optional<V> get(@NonNull String key)
{
checkNotNull(key);
LoadingCache<String, Optional<ExpiringValue<V>>> c = cache.getIfPresent(CurrentInstitution.get());
if( c != null )
{
Optional<ExpiringValue<V>> op = c.getUnchecked(key);
if( op.isPresent() )
{
V ev = op.get().getValue();
return Optional.fromNullable(ev);
}
}
return Optional.absent();
}
示例7: getMetadata
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Override
public Map<String, Map<String, String>> getMetadata(File f)
{
LoadingCache<String, Map<String, String>> metadata = CacheBuilder.newBuilder().build(
CacheLoader.from(new Function<String, Map<String, String>>()
{
@Override
public Map<String, String> apply(String input)
{
return Maps.newHashMap();
}
}));
for( MetadataHandler handler : pluginTracker.getBeanList() )
{
handler.getMetadata(metadata, f);
}
return metadata.asMap();
}
示例8: isPublic
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
/**
* Returns a boolean to denote whether a cache file is visible to all (public)
* or not
*
* @return true if the path in the current path is visible to all, false
* otherwise
*/
@Private
public static boolean isPublic(FileSystem fs, Path current, FileStatus sStat,
LoadingCache<Path,Future<FileStatus>> statCache) throws IOException {
current = fs.makeQualified(current);
//the leaf level file should be readable by others
if (!checkPublicPermsForAll(fs, sStat, FsAction.READ_EXECUTE, FsAction.READ)) {
return false;
}
if (Shell.WINDOWS && fs instanceof LocalFileSystem) {
// Relax the requirement for public cache on LFS on Windows since default
// permissions are "700" all the way up to the drive letter. In this
// model, the only requirement for a user is to give EVERYONE group
// permission on the file and the file will be considered public.
// This code path is only hit when fs.default.name is file:/// (mainly
// in tests).
return true;
}
return ancestorsHaveExecutePermissions(fs, current.getParent(), statCache);
}
示例9: handleInitContainerResources
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
/**
* For each of the requested resources for a container, determines the
* appropriate {@link LocalResourcesTracker} and forwards a
* {@link LocalResourceRequest} to that tracker.
*/
private void handleInitContainerResources(
ContainerLocalizationRequestEvent rsrcReqs) {
Container c = rsrcReqs.getContainer();
// create a loading cache for the file statuses
LoadingCache<Path,Future<FileStatus>> statCache =
CacheBuilder.newBuilder().build(FSDownload.createStatusCacheLoader(getConfig()));
LocalizerContext ctxt = new LocalizerContext(
c.getUser(), c.getContainerId(), c.getCredentials(), statCache);
Map<LocalResourceVisibility, Collection<LocalResourceRequest>> rsrcs =
rsrcReqs.getRequestedResources();
for (Map.Entry<LocalResourceVisibility, Collection<LocalResourceRequest>> e :
rsrcs.entrySet()) {
LocalResourcesTracker tracker =
getLocalResourcesTracker(e.getKey(), c.getUser(),
c.getContainerId().getApplicationAttemptId()
.getApplicationId());
for (LocalResourceRequest req : e.getValue()) {
tracker.handle(new ResourceRequestEvent(req, e.getKey(), ctxt));
}
}
}
示例10: checkPatternAt
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Nullable
/**
* checks that the given pattern & rotation is at the block co-ordinates.
*/
private BlockPattern.PatternHelper checkPatternAt(BlockPos pos, EnumFacing finger, EnumFacing thumb, LoadingCache<BlockPos, BlockWorldState> lcache)
{
for (int i = 0; i < this.palmLength; ++i)
{
for (int j = 0; j < this.thumbLength; ++j)
{
for (int k = 0; k < this.fingerLength; ++k)
{
if (!this.blockMatches[k][j][i].apply(lcache.getUnchecked(translateOffset(pos, finger, thumb, i, j, k))))
{
return null;
}
}
}
}
return new BlockPattern.PatternHelper(pos, finger, thumb, lcache, this.palmLength, this.thumbLength, this.fingerLength);
}
示例11: OidcIdTokenSigningAndEncryptionService
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
public OidcIdTokenSigningAndEncryptionService(final LoadingCache<String, Optional<RsaJsonWebKey>> defaultJsonWebKeystoreCache,
final LoadingCache<OidcRegisteredService, Optional<RsaJsonWebKey>> serviceJsonWebKeystoreCache,
final String issuer) {
this.defaultJsonWebKeystoreCache = defaultJsonWebKeystoreCache;
this.serviceJsonWebKeystoreCache = serviceJsonWebKeystoreCache;
this.issuer = issuer;
}
示例12: oidcServiceJsonWebKeystoreCache
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Bean
public LoadingCache<OidcRegisteredService, Optional<RsaJsonWebKey>> oidcServiceJsonWebKeystoreCache() {
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final LoadingCache<OidcRegisteredService, Optional<RsaJsonWebKey>> cache =
CacheBuilder.newBuilder().maximumSize(1)
.expireAfterWrite(oidc.getJwksCacheInMinutes(), TimeUnit.MINUTES)
.build(oidcServiceJsonWebKeystoreCacheLoader());
return cache;
}
示例13: oidcDefaultJsonWebKeystoreCache
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
@Bean
public LoadingCache<String, Optional<RsaJsonWebKey>> oidcDefaultJsonWebKeystoreCache() {
final OidcProperties oidc = casProperties.getAuthn().getOidc();
final LoadingCache<String, Optional<RsaJsonWebKey>> cache =
CacheBuilder.newBuilder().maximumSize(1)
.expireAfterWrite(oidc.getJwksCacheInMinutes(), TimeUnit.MINUTES)
.build(oidcDefaultJsonWebKeystoreCacheLoader());
return cache;
}
示例14: PatternHelper
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
public PatternHelper(BlockPos posIn, EnumFacing fingerIn, EnumFacing thumbIn, LoadingCache<BlockPos, BlockWorldState> lcacheIn, int p_i46378_5_, int p_i46378_6_, int p_i46378_7_)
{
this.frontTopLeft = posIn;
this.forwards = fingerIn;
this.up = thumbIn;
this.lcache = lcacheIn;
this.width = p_i46378_5_;
this.height = p_i46378_6_;
this.depth = p_i46378_7_;
}
示例15: createCache
import com.google.common.cache.LoadingCache; //導入依賴的package包/類
private static <T> LoadingCache<Class<T>, AtomicInteger> createCache(
Class<T> klass) {
return CacheBuilder.newBuilder().build(
new CacheLoader<Class<T>, AtomicInteger>() {
@Override
public AtomicInteger load(Class<T> key) throws Exception {
return new AtomicInteger();
}
});
}