Skip to content

Commit

Permalink
Update StorageManager.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Jun 29, 2024
1 parent 9ba758c commit 7587acb
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/Shiny.Mediator.Maui/Infrastructure/Impl/StorageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class StorageManager(IFileSystem fileSystem) : IStorageManager
Dictionary<string, string> keys = null!;


public void Store(object request, object result, bool isPersistent)
public virtual void Store(object request, object result, bool isPersistent)
{
if (isPersistent)
{
Expand All @@ -27,7 +27,7 @@ public void Store(object request, object result, bool isPersistent)
}


public TResult? Get<TResult>(object request, bool isPersistent)
public virtual TResult? Get<TResult>(object request, bool isPersistent)
{
TResult? returnValue = default;

Expand Down Expand Up @@ -55,8 +55,10 @@ public void Store(object request, object result, bool isPersistent)
}
return returnValue;
}


public void ClearAll()
// TODO: clear by category (cache/replay/offline)
public virtual void ClearAll()
{
lock (this.memCache)
this.memCache.Clear();
Expand All @@ -69,7 +71,7 @@ public void ClearAll()
}


string GetStoreKeyFromRequest(object request)
protected virtual string GetStoreKeyFromRequest(object request)
{
if (request is IRequestKey keyProvider)
return keyProvider.GetKey();
Expand Down Expand Up @@ -111,12 +113,12 @@ protected virtual string GetFilePath(object request, bool createIfNotExists)


bool initialized = false;
void EnsureKeyLoad()
protected void EnsureKeyLoad()
{
if (this.initialized)
return;

var storePath = Path.Combine(fileSystem.AppDataDirectory, "keys.mediator");
var storePath = this.KeyStorePath;
if (File.Exists(storePath))
{
var json = File.ReadAllText(storePath);
Expand All @@ -130,10 +132,12 @@ void EnsureKeyLoad()
}


void PersistKeyStore()
protected void PersistKeyStore()
{
var storePath = Path.Combine(fileSystem.AppDataDirectory, "keys.mediator");
var json = JsonSerializer.Serialize(this.keys);
File.WriteAllText(storePath, json);
File.WriteAllText(this.KeyStorePath, json);
}


protected string KeyStorePath => Path.Combine(fileSystem.AppDataDirectory, "keys.mediator");
}

0 comments on commit 7587acb

Please sign in to comment.