52 lines
1.4 KiB
C#
52 lines
1.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace ResourceLoading
|
|
{
|
|
|
|
public class Cache
|
|
{
|
|
private Dictionary<string, Resource> _permanentResources = new Dictionary<string, Resource>();
|
|
private Dictionary<string, Resource> _temporaryResources = new Dictionary<string, Resource>();
|
|
|
|
|
|
internal bool FindResource(string uri, out Resource resource)
|
|
{
|
|
if (!_permanentResources.TryGetValue(uri, out resource))
|
|
return _temporaryResources.TryGetValue(uri, out resource);
|
|
return true;
|
|
}
|
|
|
|
internal void AddResource(string uri, Resource resource, bool permanent)
|
|
{
|
|
if (permanent)
|
|
{
|
|
_permanentResources.Add(uri, resource);
|
|
// increase ref count for permanent resources
|
|
// in order to never release them
|
|
resource.incRefCount();
|
|
}
|
|
else
|
|
{
|
|
_temporaryResources.Add(uri, resource);
|
|
}
|
|
}
|
|
|
|
internal void RemoveResource(string uri)
|
|
{
|
|
if (_permanentResources.ContainsKey(uri))
|
|
{
|
|
Resource res = null;
|
|
_permanentResources.TryGetValue(uri, out res);
|
|
res.decRefCount();
|
|
_permanentResources.Remove(uri);
|
|
}
|
|
else if (_temporaryResources.ContainsKey(uri))
|
|
{
|
|
_temporaryResources.Remove (uri);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace JDCompanionApp.Resources
|
|
|