First commit

This commit is contained in:
Sindre G. Langhus
2016-11-29 00:37:45 +01:00
parent 4cf6d8e03f
commit 05fcd5f076

View File

@@ -0,0 +1,23 @@
using System;
using System.Reflection;
using System.Threading.Tasks;
using TId = Discord.IEntity<ulong>;
namespace Discord
{
public abstract class Cache<T> where T : IEntity<ulong>
{
public bool IsCached => Value != null;
public TId Id { get; }
public T Value { get; }
protected Cache(TId id)
{
Id = id;
}
public async Task<T> DownloadAsync() => typeof(T).GetRuntimeMethod("DownloadAsync",{ulong id});
public async Task<T> GetOrDownloadAsync() => IsCached ? Value : await DownloadAsync();
}
}