-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provides a built in caching solution for
Get
requests to enable eas…
…ier querying for data in an offline context.
- Loading branch information
1 parent
8608ffc
commit a079651
Showing
16 changed files
with
512 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Postgrest.Interfaces | ||
{ | ||
/// <summary> | ||
/// A caching provider than can be used by postgrest to store requests. | ||
/// </summary> | ||
public interface IPostgrestCacheProvider | ||
{ | ||
/// <summary> | ||
/// Gets an item from a caching solution, should coerce into a datatype. | ||
/// | ||
/// This will most likely be a JSON deserialization approach. | ||
/// </summary> | ||
/// <param name="key">A reproducible key for a defined query.</param> | ||
/// <typeparam name="T"></typeparam> | ||
/// <returns></returns> | ||
public Task<T?> GetItem<T>(string key); | ||
|
||
/// <summary> | ||
/// Sets an item within a caching solution, should store in a way that the data can be retrieved and coerced into a generic type by <see cref="GetItem{T}"/> | ||
/// | ||
/// This will most likely be a JSON serialization approach. | ||
/// </summary> | ||
/// <param name="key">A reproducible key for a defined query.</param> | ||
/// <param name="value">An object of serializable data.</param> | ||
/// <returns></returns> | ||
public Task SetItem(string key, object value); | ||
|
||
/// <summary> | ||
/// Clear an item within a caching solution by a key. | ||
/// </summary> | ||
/// <param name="key">A reproducible key for a defined query.</param> | ||
/// <returns></returns> | ||
public Task ClearItem(string key); | ||
|
||
/// <summary> | ||
/// An empty/clear cache implementation. | ||
/// </summary> | ||
/// <returns></returns> | ||
public Task Empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Postgrest.Models; | ||
using Postgrest.Requests; | ||
|
||
namespace Postgrest.Interfaces | ||
{ | ||
/// <summary> | ||
/// Client interface for Postgrest | ||
/// </summary> | ||
/// <typeparam name="T"></typeparam> | ||
public interface IPostgrestTableWithCache<T> : IPostgrestTable<T> where T : BaseModel, new() | ||
{ | ||
/// <summary> | ||
/// Performs a Get request, returning a <see cref="CacheBackedRequest{TModel}"/> which populates from the cache, if applicable. | ||
/// </summary> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
public new Task<CacheBackedRequest<T>> Get(CancellationToken cancellationToken = default); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Newtonsoft.Json; | ||
|
||
namespace Postgrest.Models | ||
{ | ||
/// <summary> | ||
/// Represents a cacheable model | ||
/// </summary> | ||
/// <typeparam name="TModel"></typeparam> | ||
public class CachedModel<TModel> where TModel : BaseModel, new() | ||
{ | ||
/// <summary> | ||
/// The stored Models | ||
/// </summary> | ||
[JsonProperty("response")] public List<TModel>? Models { get; set; } | ||
|
||
/// <summary> | ||
/// Cache time in UTC. | ||
/// </summary> | ||
[JsonProperty("cachedAt")] public DateTime CachedAt { get; set; } | ||
} | ||
} |
Oops, something went wrong.