Show / Hide Table of Contents

# Struct Cacheable<TEntity, TId>

Represents a cached entity.

##### Inherited Members

System.ValueType.Equals(System.Object)
System.ValueType.GetHashCode()
System.ValueType.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()

###### Namespace: Discord

###### Assembly: Discord.Net.Core.dll

##### Syntax

    public struct Cacheable<TEntity, TId>

        where TEntity : IEntity<TId> where TId : IEquatable<TId>

##### Type Parameters

Name | Description
--- | ---
TEntity | The type of entity that is cached.
TId | The type of this entity's ID.

### Properties

| Improve this Doc View Source

#### HasValue

Gets whether this entity is cached.

##### Declaration

    public bool HasValue { get; }

##### Property Value

Type | Description
--- | ---
System.Boolean |

| Improve this Doc View Source

#### Id

Gets the ID of this entity.

##### Declaration

    public TId Id { get; }

##### Property Value

Type | Description
--- | ---
TId |

| Improve this Doc View Source

#### Value

Gets the entity if it could be pulled from cache.

##### Declaration

    public TEntity Value { get; }

##### Property Value

Type | Description
--- | ---
TEntity |

##### Remarks

This value is not guaranteed to be set; in cases where the entity cannot be pulled from cache, it is `null`.

### Methods

| Improve this Doc View Source

#### DownloadAsync()

Downloads this entity to cache.

##### Declaration

    public Task<TEntity> DownloadAsync()

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.Task<TEntity> | A task that represents the asynchronous download operation. The task result contains the downloaded entity.

##### Exceptions

Type | Condition
--- | ---
Discord.Net.HttpException | Thrown when used from a user account.
System.NullReferenceException | Thrown when the message is deleted.

| Improve this Doc View Source

#### GetOrDownloadAsync()

Returns the cached entity if it exists; otherwise downloads it.

##### Declaration

    public Task<TEntity> GetOrDownloadAsync()

##### Returns

Type | Description
--- | ---
System.Threading.Tasks.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

Type | Condition
--- | ---
Discord.Net.HttpException | Thrown when used from a user account.
System.NullReferenceException | Thrown when the message is deleted and is not in cache.