当前位置: 首页>>代码示例>>Java>>正文


Java Cache.getIfPresent方法代码示例

本文整理汇总了Java中com.google.common.cache.Cache.getIfPresent方法的典型用法代码示例。如果您正苦于以下问题:Java Cache.getIfPresent方法的具体用法?Java Cache.getIfPresent怎么用?Java Cache.getIfPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.cache.Cache的用法示例。


在下文中一共展示了Cache.getIfPresent方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getChronoRange

import com.google.common.cache.Cache; //导入方法依赖的package包/类
/**
 * Create a ChronoRange for the given ChronoSeries and sequence of ChronoGenes.
 *
 * @param chronoSeries ChronoSeries to create ChronoRange for
 * @param genes ChronoGene sequence containing ChronoPattern(s) to use for creating ChronoRange
 * @return ChronoRange for given ChronoSeries and ChronoGene sequence
 */
@NotNull
public static ChronoRange getChronoRange(@NotNull ChronoSeries chronoSeries, @NotNull ISeq<ChronoGene> genes) {
    ChronoRange range = new ChronoRange(requireNonNull(chronoSeries), requireNonNull(genes));
    Cache<ISeq<ChronoPattern>, ChronoRange> cacheChronoRange = cacheMap.get(chronoSeries);
    if (cacheChronoRange == null) {
        cacheChronoRange = CacheBuilder.newBuilder().build();
        cacheMap.put(chronoSeries, cacheChronoRange);
    }

    ChronoRange cacheRange = cacheChronoRange.getIfPresent(range.chronoPatternSeq);
    if (cacheRange != null) {
        return cacheRange;
    } else {
        if (range.validRange) {
            range.calculateTimestampRanges();
        }

        cacheChronoRange.put(range.chronoPatternSeq, range);
        return range;
    }
}
 
开发者ID:BFergerson,项目名称:Chronetic,代码行数:29,代码来源:ChronoRange.java

示例2: getUserState

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Override
public OAuthUserState getUserState(String tokenData, HttpServletRequest request)
{
	Cache<String, OAuthUserState> userCache = getUserCache(CurrentInstitution.get());
	OAuthUserState oauthUserState = userCache.getIfPresent(tokenData);
	if( oauthUserState == null )
	{
		// find the token and the user associated with it
		final OAuthToken token = oauthService.getToken(tokenData);
		if( token == null )
		{
			// FIXME: Need to fall back on server language since
			// LocaleEncodingFilter has not run yet...
			throw new OAuthException(403, OAuthConstants.ERROR_ACCESS_DENIED, languageService
				.getResourceBundle(Locale.getDefault(), "resource-centre").getString(KEY_TOKEN_NOT_FOUND));
		}

		final UserState userState = userService.authenticateAsUser(token.getUsername(),
			userService.getWebAuthenticationDetails(request));

		oauthUserState = new OAuthUserStateImpl(userState, token);
		userCache.put(tokenData, oauthUserState);
	}
	return (OAuthUserState) oauthUserState.clone();
}
 
开发者ID:equella,项目名称:Equella,代码行数:26,代码来源:OAuthWebServiceImpl.java

示例3: getFromCache

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> T getFromCache(Object key, String property, final CacheLoader<String, T> loader)
{
	Cache<Object, Object> map = cache.getCache();

	Object ro = map.getIfPresent(key);
	if( ro == null )
	{
		T newObj = loadFromDb(property, loader);
		synchronized( map )
		{
			map.put(key, newObj != null ? newObj : CACHED_NULL);
			return newObj;
		}
	}
	else
	{
		return ro.equals(CACHED_NULL) ? null : (T) ro;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:21,代码来源:ConfigurationServiceImpl.java

示例4: schemaCacheItemsGetAddedUponInstanceAccess

import com.google.common.cache.Cache; //导入方法依赖的package包/类
public void schemaCacheItemsGetAddedUponInstanceAccess() {
    // Initially there should be no entries on the schemaDescriptionIdCache
    Cache<SchemaKey, Set<SchemaKey>> schemaDescriptionIdCache = cacheService.getSchemaDescriptionIdCache();
    assertEquals(schemaDescriptionIdCache.size(), 0);

    // Creating auxiliary objects prior to execute queries
    Map<String, Object> variableMap = buildVariableMap(CACHE_TEST_NAMESPACE, MEDIA_DOMAIN_NAME);

    SchemaWriteAccess access = buildSchemaWriteAccessCacheTestNamespace();

    // Run a query on media that should populate the reference cache for it
    GraphQLResult addMediaInstanceResult = instanceService.executeQuery(addMediaInstance, variableMap, access, DEFAULT_MAX_RECURSE_DEPTH);
    assertTrue(addMediaInstanceResult.isSuccessful());

    // Lookup for "Media" referenced types
    Set<SchemaKey> schemaKeySets = schemaDescriptionIdCache.getIfPresent(new SchemaKey(MEDIA_DOMAIN_NAME, SCHEMA_NAME_SPACE));

    // Media should have 2 referenced types (Video and Audio)
    assertNotNull(schemaKeySets);
    assertEquals(schemaKeySets.size(), 2);

    assertTrue(schemaKeySets.contains(new SchemaKey(VIDEO_DOMAIN_NAME, SCHEMA_NAME_SPACE)));
    assertTrue(schemaKeySets.contains(new SchemaKey(AUDIO_DOMAIN_NAME, SCHEMA_NAME_SPACE)));
}
 
开发者ID:nfl,项目名称:gold,代码行数:25,代码来源:SchemaDefinitionCacheTest.java

示例5: fetchDormantChunk

import com.google.common.cache.Cache; //导入方法依赖的package包/类
public static Chunk fetchDormantChunk(long coords, World world)
{
    if (dormantChunkCacheSize == 0) return null; // Don't bother with maps at all if its never gonna get a response
    Cache<Long, Chunk> cache = dormantChunkCache.get(world);
    if (cache == null)
    {
        return null;
    }
    Chunk chunk = cache.getIfPresent(coords);
    if (chunk != null)
    {
        for (ClassInheritanceMultiMap<Entity> eList : chunk.getEntityLists())
        {
            Iterator<Entity> itr = eList.iterator();
            while (itr.hasNext())
            {
                (itr.next()).resetEntityId();
            }
        }
    }
    return chunk;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:23,代码来源:ForgeChunkManager.java

示例6: getResponse

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private <K, V> Response<V> getResponse(Key<K> key, Cache<Key<K>, Response<V>> cache, Factory<Response<V>> responseFactory, Transformer<Key<K>, ? super Response<V>> keyGenerator) {
    Response<V> response = key == null ? null : cache.getIfPresent(key);
    if (response != null) {
        return response;
    } else {
        response = responseFactory.create();
        if (!response.isError()) {
            Key<K> actualKey = keyGenerator.transform(response);
            cache.put(actualKey, response);
        }
        return response;
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:InMemoryCachingPluginResolutionServiceClient.java

示例7: getTree

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private DefaultSectionTree getTree(String userId)
{
	long institutionId = CurrentInstitution.get().getUniqueId();
	Cache<String, DefaultSectionTree> instMap = sectionCache.getIfPresent(institutionId);
	if( instMap == null )
	{
		instMap = CacheBuilder.newBuilder().softValues().expireAfterAccess(30, TimeUnit.MINUTES).build();
		sectionCache.put(institutionId, instMap);
	}
	return instMap.getIfPresent(userId);
}
 
开发者ID:equella,项目名称:Equella,代码行数:12,代码来源:PortletWebServiceImpl.java

示例8: getDataSource

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private TaxonomyDataSource getDataSource(final String uuid)
{
	synchronized( cacheLock )
	{
		Institution inst = CurrentInstitution.get();
		Cache<String, TaxonomyDataSource> instEntry = dataSourceCache.getIfPresent(inst);
		if( instEntry == null )
		{
			instEntry = CacheBuilder.newBuilder().softValues().expireAfterAccess(1, TimeUnit.HOURS).build();
			dataSourceCache.put(inst, instEntry);
		}

		TaxonomyDataSource tds = instEntry.getIfPresent(uuid);
		if( tds == null )
		{
			final Taxonomy taxonomy = getDao().getByUuid(uuid);
			if( taxonomy == null )
			{
				throw new NotFoundException("Could not find taxonomy with UUID " + uuid);
			}

			tds = getDataSourceNoCache(taxonomy);
			instEntry.put(uuid, tds);
		}
		return tds;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:28,代码来源:TaxonomyServiceImpl.java

示例9: onAccept

import com.google.common.cache.Cache; //导入方法依赖的package包/类
public boolean onAccept(Event event) {
    Pair<String, Object> key = ImmutablePair.of(event.getName(), event.get(getAttributeName()));

    Cache<Pair<String, Object>, Boolean> cache = getCache();
    synchronized (cache) {
        boolean hasOccured = cache.getIfPresent(key) != null;

        if (!hasOccured) {
            cache.put(key, true);
            return true;
        } else {
            return false;
        }
    }
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:16,代码来源:Deduplication.java

示例10: getConnection

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private static Connection getConnection(JdbcMeta m, String id) throws Exception {
  Field f = JdbcMeta.class.getDeclaredField("connectionCache");
  f.setAccessible(true);
  //noinspection unchecked
  Cache<String, Connection> connectionCache = (Cache<String, Connection>) f.get(m);
  return connectionCache.getIfPresent(id);
}
 
开发者ID:apache,项目名称:calcite-avatica,代码行数:8,代码来源:RemoteMetaTest.java

示例11: getArrayProperty

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Override
public String[] getArrayProperty(String key, final String delimiter, String[] defaultValue) {
  try {
    if (!m_arrayCache.containsKey(delimiter)) {
      synchronized (this) {
        if (!m_arrayCache.containsKey(delimiter)) {
          m_arrayCache.put(delimiter, this.<String[]>newCache());
        }
      }
    }

    Cache<String, String[]> cache = m_arrayCache.get(delimiter);
    String[] result = cache.getIfPresent(key);

    if (result != null) {
      return result;
    }

    return getValueAndStoreToCache(key, new Function<String, String[]>() {
      @Override
      public String[] apply(String input) {
        return input.split(delimiter);
      }
    }, cache, defaultValue);
  } catch (Throwable ex) {
    Tracer.logError(new ApolloConfigException(
        String.format("getArrayProperty for %s failed, return default value", key), ex));
  }
  return defaultValue;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:31,代码来源:AbstractConfig.java

示例12: getValueFromCache

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private <T> T getValueFromCache(String key, Function<String, T> parser, Cache<String, T> cache, T defaultValue) {
  T result = cache.getIfPresent(key);

  if (result != null) {
    return result;
  }

  return getValueAndStoreToCache(key, parser, cache, defaultValue);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:10,代码来源:AbstractConfig.java


注:本文中的com.google.common.cache.Cache.getIfPresent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。