Code example for Cache

Methods: getIfPresent

0
        m_attributeMisses = registry.meter(name(getClass(), "attribute-misses"));
    } 
 
    @Override 
    public Optional<ResourceMetadata> get(Context context, Resource resourceId) {
        ResourceMetadata r = m_cache.getIfPresent(key(context, resourceId));
        return (r != null) ? Optional.of(r) : Optional.<ResourceMetadata>absent();
    } 
 
    private String key(Context context, Resource resource) {
        return m_keyJoiner.join(context.getId(), resource.getId());
    } 
 
    @Override 
    public void merge(Context context, Resource resource, ResourceMetadata metadata) {
 
        Optional<ResourceMetadata> o = get(context, resource);
 
        if (!o.isPresent()) {
            ResourceMetadata newMetadata = new ResourceMetadata(m_metricReqs, m_attributeReqs, m_metricMisses, m_attributeMisses);