Skip to content

Commit

Permalink
Add missing storage methods for cache servicing
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Dec 28, 2024
1 parent b9c7f9f commit a20e06e
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ public interface IStorageService
Task Set<T>(string key, T value);
Task<T?> Get<T>(string key);
Task Remove(string key);
Task RemoveByPrefix(string prefix);
Task Clear();
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,8 @@ public Task Set<T>(string key, T value, CacheItemConfig? config = null)


public Task Remove(string key) => storage.Remove(key);
public Task RemoveByPrefix(string prefix)
{
// TODO: not available in storage service
throw new NotImplementedException();
}

public Task Clear()
{
// TODO: not available in storage service
throw new NotImplementedException();
}

public Task RemoveByPrefix(string prefix) => storage.RemoveByPrefix(prefix);
public Task Clear() => storage.Clear();

async Task<InternalCacheEntry<T>> Store<T>(string key, T result, CacheItemConfig? config)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Shiny.Mediator.Blazor/Infrastructure/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,18 @@ public Task Remove(string key)
inproc.InvokeVoid("MediatorServices.removeStore", key);
return Task.CompletedTask;
}

public Task RemoveByPrefix(string prefix)
{
var inproc = (IJSInProcessRuntime)jsruntime;
inproc.InvokeVoid("MediatorServices.removeByPrefix", prefix);
return Task.CompletedTask;
}

public Task Clear()
{
var inproc = (IJSInProcessRuntime)jsruntime;
inproc.InvokeVoid("MediatorServices.clearStore");
return Task.CompletedTask;
}
}
11 changes: 11 additions & 0 deletions src/Shiny.Mediator.Blazor/wwwroot/Mediator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,16 @@ window.MediatorServices = {

removeStore: function(key) {
localStorage.removeItem(key);
},

removeByPrefix: function(key) {
Object.keys(localStorage).forEach(key => {
if (key.startsWith(key))
delete localStorage[key];
})
},

clearStore: function() {
localStorage.clear();
}
};
14 changes: 14 additions & 0 deletions src/Shiny.Mediator.Maui/Infrastructure/StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,18 @@ public Task Remove(string key)

return Task.CompletedTask;
}

public Task RemoveByPrefix(string prefix) => this.DeleteBy(prefix + "*.mediator");
public Task Clear() => this.DeleteBy("*.mediator");


Task DeleteBy(string pattern)
{
var dir = new DirectoryInfo(fileSystem.CacheDirectory);
var files = dir.GetFiles(pattern);
foreach (var file in files)
file.Delete();

return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<ItemGroup>
<!--4.11 does not generate in project refs on rider-->
<PackageReference Include="SharpYaml" Version="2.1.1" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.22" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.22" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.OpenApi" Version="1.6.23" PrivateAssets="All" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.23" PrivateAssets="All" GeneratePathProperty="true" />

<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
Expand Down
12 changes: 12 additions & 0 deletions src/Shiny.Mediator/StreamExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Shiny.Mediator;

public class StreamExecutionContext(CancellationToken cancellationToken) //IStreamRequestHandler<>)
{
public Guid ExecutionId { get; }= Guid.NewGuid();
public CancellationToken CancellationToken => cancellationToken;

// TODO: for each pump, I can set a execution #
// TODO: pump 1 is from cache
// TODO: pump 2 is from offline
// TODO: pump 3 is from live
}
2 changes: 1 addition & 1 deletion tests/Shiny.Mediator.Tests/Shiny.Mediator.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageReference Include="FluentAssertions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.5.0" />
<PackageReference Include="MartinCostello.Logging.XUnit" Version="0.5.1" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down

0 comments on commit a20e06e

Please sign in to comment.