get method
Returns a ResourceContent using resource
as key.
If the cache already have a resolved ResourceContent will prioritize it and return it.
resource
can be of type Resource
, ResourceContent, Uri or Uri string.
Implementation
ResourceContent? get(Object? resource) {
if (resource == null) return null;
var resourceContent = ResourceContent.from(resource)!;
var cacheKey = _cacheKey(resourceContent);
if (cacheKey == null) return resourceContent;
var cached = _resources[cacheKey];
if (cached != null) {
if (identical(cached, resourceContent)) return resourceContent;
if (resourceContent.hasContent && !cached.hasContent) {
var content = resourceContent._content;
cached._content = content;
cached.onLoad.add(content);
}
return cached;
}
_resources[cacheKey] = resourceContent;
return resourceContent;
}