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


Java Cache.put方法代码示例

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


在下文中一共展示了Cache.put方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: guavaCache

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Test
public void guavaCache() throws InterruptedException {

    TesTicker ticker = new TesTicker();
    Cache<String, Pojo> collection = CacheBuilder.newBuilder().expireAfterAccess(5, TimeUnit.SECONDS).ticker(ticker)
            .<String, Pojo> build();
    Pojo p1 = new Pojo("p1name", "p1val");
    Pojo p2 = new Pojo("p2name", "p2val");
    collection.put("p1", p1);
    collection.put("p2", p2);
    ticker.advance(3, TimeUnit.SECONDS);
    Map<String, Pojo> map = collection.asMap();
    assertTrue(map.containsKey("p1"));
    // map.get("p1");
    ticker.advance(3, TimeUnit.SECONDS);
    assertEquals(2, collection.size());
    assertFalse(map.containsKey("p1"));// 有清除过期操作
    assertEquals(1, collection.size());
    assertNull(collection.getIfPresent("p2"));
    assertNull(collection.getIfPresent("p1"));// 有清除过期操作
    assertEquals(0, collection.size());
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:DoTestRuleFilterFactory.java

示例5: getValueAndStoreToCache

import com.google.common.cache.Cache; //导入方法依赖的package包/类
private <T> T getValueAndStoreToCache(String key, Function<String, T> parser, Cache<String, T> cache, T defaultValue) {
  long currentConfigVersion = m_configVersion.get();
  String value = getProperty(key, null);

  if (value != null) {
    T result = parser.apply(value);

    if (result != null) {
      synchronized (this) {
        if (m_configVersion.get() == currentConfigVersion) {
          cache.put(key, result);
        }
      }
      return result;
    }
  }

  return defaultValue;
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:20,代码来源:AbstractConfig.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: getPortletRendererTree

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Override
public SectionTree getPortletRendererTree(SectionInfo info)
{
	String userId = CurrentUser.getUserID();
	DefaultSectionTree tree = getTree(userId);
	if( tree == null )
	{
		tree = buildRendererTree(info, userId);
		final Cache<String, DefaultSectionTree> instMap = sectionCache
			.getIfPresent(CurrentInstitution.get().getUniqueId());
		instMap.put(userId, tree);
	}
	return tree;
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源: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: set

import com.google.common.cache.Cache; //导入方法依赖的package包/类
public boolean set(String cacheName, String key, Object value) {
    if (value == null) { return true; }
    Cache<String, Object> cache = getCacheHolder(cacheName);
    if (cache != null) {
        cache.put(key, value);
    }
    return true;
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:9,代码来源:GuavaLevel1CacheProvider.java

示例11: testHandleMessage

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Test
public void testHandleMessage() throws Exception {
  String someWatchKey = "someWatchKey";
  String anotherWatchKey = "anotherWatchKey";
  String someCacheKey = "someCacheKey";
  String anotherCacheKey = "anotherCacheKey";
  String someValue = "someValue";

  ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
  when(someReleaseMessage.getMessage()).thenReturn(someWatchKey);

  Cache<String, String> cache =
      (Cache<String, String>) ReflectionTestUtils.getField(configFileController, "localCache");
  cache.put(someCacheKey, someValue);
  cache.put(anotherCacheKey, someValue);

  watchedKeys2CacheKey.putAll(someWatchKey, Lists.newArrayList(someCacheKey, anotherCacheKey));
  watchedKeys2CacheKey.putAll(anotherWatchKey, Lists.newArrayList(someCacheKey, anotherCacheKey));

  cacheKey2WatchedKeys.putAll(someCacheKey, Lists.newArrayList(someWatchKey, anotherWatchKey));
  cacheKey2WatchedKeys.putAll(anotherCacheKey, Lists.newArrayList(someWatchKey, anotherWatchKey));

  configFileController.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);

  assertTrue(watchedKeys2CacheKey.isEmpty());
  assertTrue(cacheKey2WatchedKeys.isEmpty());
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:28,代码来源:ConfigFileControllerTest.java

示例12: putDormantChunk

import com.google.common.cache.Cache; //导入方法依赖的package包/类
public static void putDormantChunk(long coords, Chunk chunk)
{
    if (dormantChunkCacheSize == 0) return; // Skip if we're not dormant caching chunks
    Cache<Long, Chunk> cache = dormantChunkCache.get(chunk.getWorld());
    if (cache != null)
    {
        cache.put(coords, chunk);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:10,代码来源:ForgeChunkManager.java

示例13: put

import com.google.common.cache.Cache; //导入方法依赖的package包/类
@Override
public void put(String cacheName, String key, Object value) {
    Cache<String, Object> cache = getCache(cacheName);
    cache.put(key, value);
}
 
开发者ID:BriData,项目名称:DBus,代码行数:6,代码来源:GuavaLocalCache.java


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