Struct Cacheable<TEntity, TId>
- Namespace
- Discord
- Assembly
- Discord.Net.Core.dll
Represents a cached entity.
public struct Cacheable<TEntity, TId> where TEntity : IEntity<TId> where TId : IEquatable<TId>
Type Parameters
TEntity
The type of entity that is cached.
TId
The type of this entity's ID.
- Inherited Members
Properties
HasValue
Gets whether this entity is cached.
public readonly bool HasValue { get; }
Property Value
Id
Gets the ID of this entity.
public readonly TId Id { get; }
Property Value
- TId
Value
Gets the entity if it could be pulled from cache.
public readonly TEntity Value { get; }
Property Value
- TEntity
Remarks
This value is not guaranteed to be set; in cases where the entity cannot be pulled from cache, it is null.
Methods
DownloadAsync()
Downloads this entity to cache.
public Task<TEntity> DownloadAsync()
Returns
- Task<TEntity>
A task that represents the asynchronous download operation. The task result contains the downloaded entity.
Exceptions
- HttpException
Thrown when used from a user account.
- NullReferenceException
Thrown when the message is deleted.
GetOrDownloadAsync()
Returns the cached entity if it exists; otherwise downloads it.
public Task<TEntity> GetOrDownloadAsync()
Returns
- Task<TEntity>
A task that represents the asynchronous operation that attempts to get the message via cache or to download the message. The task result contains the downloaded entity.
Exceptions
- HttpException
Thrown when used from a user account.
- NullReferenceException
Thrown when the message is deleted and is not in cache.