cache assemblies in IndexedDB on WebAssembly

This commit is contained in:
Shaun Walker
2022-09-12 14:46:46 -04:00
parent 2d306e8fda
commit b8e2c729c1
4 changed files with 296 additions and 39 deletions

View File

@ -1,6 +1,12 @@
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using System.Net;
using System;
using System.Threading.Tasks;
using System.Text.Json;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Linq;
namespace Oqtane.UI
{
@ -307,5 +313,76 @@ namespace Oqtane.UI
return new ValueTask<int>(-1);
}
}
public Task SetIndexedDBItem(string key, object value)
{
try
{
_jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.setIndexedDBItem",
key, value);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
public async Task<T> GetIndexedDBItem<T>(string key)
{
try
{
return await _jsRuntime.InvokeAsync<T>(
"Oqtane.Interop.getIndexedDBItem",
key);
}
catch
{
return default(T);
}
}
public async Task<List<string>> GetIndexedDBKeys()
{
return await GetIndexedDBKeys("");
}
public async Task<List<string>> GetIndexedDBKeys(string contains)
{
try
{
var items = await _jsRuntime.InvokeAsync<JsonDocument>(
"Oqtane.Interop.getIndexedDBKeys");
if (!string.IsNullOrEmpty(contains))
{
return items.Deserialize<List<string>>()
.Where(item => item.Contains(contains)).ToList();
}
else
{
return items.Deserialize<List<string>>();
}
}
catch
{
return new List<string>();
}
}
public Task RemoveIndexedDBItem(string key)
{
try
{
_jsRuntime.InvokeVoidAsync(
"Oqtane.Interop.removeIndexedDBItem",
key);
return Task.CompletedTask;
}
catch
{
return Task.CompletedTask;
}
}
}
}