本文整理汇总了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;
}
}
示例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();
}
示例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;
}
}
示例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());
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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;
}
}
}
示例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;
}
示例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());
}
示例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);
}
}
示例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);
}