Cache asMap - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Cache asMap method.

This code example shows how to use the following methods:asMap, size
		Cache<String, Boolean> cache = CacheBuilder.newBuilder()
				.expireAfterAccess(10, TimeUnit.MILLISECONDS)
				.build();
 
		// create evicting Set out of the Cache data structures 
		Set<String> set = Sets.newSetFromMap(cache.asMap());
 
		// there are no entries initially 
		assertEquals(0, set.size());
 
		// add an entry directly in the Set (do not use Cache APIs) 
		set.add("value");
 
		// make sure the cache sees the new entry 
		assertEquals(1, cache.size());
 
		// sleep a while to expire the entry 
		Duration.milliseconds(50).sleep(); 
 
		// the entry should be considered expired now 
6
CodeRank
This code example shows how to use the following methods:asMap
			return false; 
	} 
 
	@Override 
	public Collection keySet() {
		return cache.asMap().keySet(); 
	} 
 
	@Override 
	public long getCacheHits() { 
		return cache.stats().hitCount(); 
	} 
 
	@Override 
	public long getCacheMisses() { 
		return cache.stats().missCount(); 
	} 
 
} 
5
CodeRank
This code example shows how to use the following methods:asMap, getIfPresent, put
    this.relativeId = FullName.ASSEMBLE_PATH_PARTS.apply( new String[] { "user", user.getName( ) } );
    this.qName = this.authority + this.relativeId;
  } 
   
  public static UserFullName getInstance( final String userId, final String... relativePath ) {
    if ( userIdMap.asMap().containsKey( userId ) ) {
      return userIdMap.getIfPresent( userId );
    } else { 
      try { 
        userIdMap.put( userId, getInstance( Accounts.lookupUserById( userId ), relativePath ) );
        return userIdMap.getIfPresent( userId );
      } catch ( final AuthException ex ) {
        userIdMap.put( userId, getInstance( Principals.systemUser( ), relativePath ) );
        return userIdMap.getIfPresent( userId );
      } 
    } 
  } 
   
  public static UserFullName getInstance( final User user, final String... relativePath ) {
    try { 
5
CodeRank
This code example shows how to use the following methods:asMap
    } 
     
    @Override 
    public boolean contains(K key)
    { 
        return cache.asMap().containsKey(key);
    } 
 
    @Override 
    public Collection<K> getKeys()
    { 
        return cache.asMap().keySet();
    } 
 
    @Override 
    public V get(K key)
    { 
        AbstractMap.SimpleImmutableEntry<K, V> kvp = cache.getIfPresent(key);
        if (kvp == null)
        { 
4
CodeRank
This code example shows how to use the following methods:asMap
 
  } 
 
  public FragmentManager getFragmentManager(FragmentHandle handle) throws FragmentSetupException {
    // check if this was a recently canceled fragment.  If so, throw away message. 
    if (recentlyFinishedFragments.asMap().containsKey(handle)) {
      logger.debug("Fragment: {} was cancelled. Ignoring fragment handle", handle);
      return null; 
    } 
 
    // since non-leaf fragments are sent first, it is an error condition if the manager is unavailable. 
    FragmentManager m = managers.get(handle);
    if(m != null){
      return m;
    } 
    throw new FragmentSetupException("Failed to receive plan fragment that was required for id: " + QueryIdHelper.getQueryIdentifier(handle));
  } 
 
  public void cancelFragment(FragmentHandle handle) {
    logger.debug("Fragment canceled: {}", QueryIdHelper.getQueryIdentifier(handle));
4
CodeRank
asMap Method Overview
Returns a view of the entries stored in this cache as a thread-safe map.
See Code Examples for other Guava Cache Methods: