mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 07:46:05 -07:00
Made more async goodness
This commit is contained in:
parent
8550cc4c5e
commit
166e0f81cf
7 changed files with 181 additions and 30 deletions
|
@ -27,6 +27,7 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Runtime.Caching;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlexRequests.Helpers
|
||||
{
|
||||
|
@ -65,6 +66,23 @@ namespace PlexRequests.Helpers
|
|||
return item.CloneJson();
|
||||
}
|
||||
|
||||
public async Task<T> GetOrSetAsync<T>(string key, Func<Task<T>> itemCallback, int cacheTime = 20) where T : class
|
||||
{
|
||||
var item = Get<T>(key);
|
||||
if (item == null)
|
||||
{
|
||||
item = await itemCallback();
|
||||
if (item != null)
|
||||
{
|
||||
Set(key, item, cacheTime);
|
||||
}
|
||||
}
|
||||
|
||||
// Return a copy, not the stored cache reference
|
||||
// The cached object will not change
|
||||
return item.CloneJson();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified item from the cache.
|
||||
/// </summary>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue