Browse Source

First commit

pull/395/head
Sindre G. Langhus 8 years ago
parent
commit
05fcd5f076
1 changed files with 23 additions and 0 deletions
  1. +23
    -0
      src/Discord.Net.Core/Utils/Cache.cs

+ 23
- 0
src/Discord.Net.Core/Utils/Cache.cs 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();
}
}

Loading…
Cancel
Save