Skip to content

Commit

Permalink
#3635 Update API so it works properly with async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Dec 27, 2023
1 parent 5f19934 commit 36f7672
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
6 changes: 2 additions & 4 deletions Source/Csla/DataPortalClient/DataPortalCacheDefault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class DataPortalCacheDefault : IDataPortalCache
/// <param name="criteria">Criteria for domain type being added</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Data portal result to cache</param>
/// <returns></returns>
public Task AddObject(Type objectType, object criteria, DataPortalOperations operation, DataPortalResult result)
public Task AddDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation, DataPortalResult result)
=> throw new NotImplementedException();

/// <summary>
Expand All @@ -54,9 +53,8 @@ public bool IsCacheable(Type objectType, object criteria, DataPortalOperations o
/// <param name="objectType">Type of domain object to retrieve</param>
/// <param name="criteria">Criteria for domain type being retrieved</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Cached data portal result</param>
/// <returns>true if success, false if object isn't returned</returns>
public Task<bool> TryGetObject(Type objectType, object criteria, DataPortalOperations operation, out DataPortalResult result)
public Task<DataPortalResult> GetDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation)
=> throw new NotImplementedException();
}
}
9 changes: 4 additions & 5 deletions Source/Csla/DataPortalClient/IDataPortalCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ namespace Csla.DataPortalClient
public interface IDataPortalCache
{
/// <summary>
/// Try to get object from cache.
/// Try to get result from cache.
/// </summary>
/// <param name="objectType">Type of domain object to retrieve</param>
/// <param name="criteria">Criteria for domain type being retrieved</param>
/// <param name="operation">Data portal operation</param>
/// <param name="result">Cached data portal result</param>
/// <returns>true if success, false if object isn't returned</returns>
Task<bool> TryGetObject(Type objectType, object criteria, DataPortalOperations operation, out Server.DataPortalResult result);
/// <returns>null if not in cache</returns>
Task<Server.DataPortalResult?> GetDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation);
/// <summary>
/// Add object to cache.
/// </summary>
Expand All @@ -35,7 +34,7 @@ public interface IDataPortalCache
/// <param name="operation">Data portal operation</param>
/// <param name="result">Data portal result to cache</param>
/// <returns></returns>
Task AddObject(Type objectType, object criteria, DataPortalOperations operation, Server.DataPortalResult result);
Task AddDataPortalResultAsync(Type objectType, object criteria, DataPortalOperations operation, Server.DataPortalResult result);
/// <summary>
/// Gets a value indicating whether the domain type
/// can be cached.
Expand Down
25 changes: 15 additions & 10 deletions Source/Csla/DataPortalT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ private async Task<object> DoCreateAsync(Type objectType, object criteria, bool
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Create, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Create);
if (result is null)
{
result = await proxy.Create(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Create, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Create, result);
}
}
finally
Expand Down Expand Up @@ -246,10 +247,11 @@ private async Task<object> DoFetchAsync(Type objectType, object criteria, bool i
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Fetch, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Fetch);
if (result is null)
{
result = await proxy.Fetch(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Fetch, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Fetch, result);
}
}
finally
Expand Down Expand Up @@ -310,10 +312,11 @@ private async Task<object> DoExecuteAsync(Type objectType, object criteria, bool
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Execute, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Execute);
if (result is null)
{
result = await proxy.Fetch(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Execute, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Execute, result);
}
}
finally
Expand Down Expand Up @@ -543,10 +546,11 @@ internal async Task<T> DoUpdateAsync(T obj, bool isSync)
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, obj, operation, out result))
result = await Cache.GetDataPortalResultAsync(objectType, obj, operation);
if (result is null)
{
result = await proxy.Update(obj, dpContext, isSync);
await Cache.AddObject(objectType, obj, operation, result);
await Cache.AddDataPortalResultAsync(objectType, obj, operation, result);
}
}
finally
Expand Down Expand Up @@ -651,10 +655,11 @@ internal async Task DoDeleteAsync(Type objectType, object criteria, bool isSync)
try
{
await Cache.Semaphore.WaitAsync();
if (!await Cache.TryGetObject(objectType, criteria, DataPortalOperations.Delete, out result))
result = await Cache.GetDataPortalResultAsync(objectType, criteria, DataPortalOperations.Delete);
if (result is null)
{
result = await proxy.Delete(objectType, criteria, dpContext, isSync);
await Cache.AddObject(objectType, criteria, DataPortalOperations.Delete, result);
await Cache.AddDataPortalResultAsync(objectType, criteria, DataPortalOperations.Delete, result);
}
}
finally
Expand Down
12 changes: 7 additions & 5 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ CSLA .NET version 8.0.0 adds support for .NET 8 and other enhancements.
* [#3463](https://github.com/MarimerLLC/csla/issues/3463) Remove .NET Core 3.1 code
* [#3491](https://github.com/MarimerLLC/csla/issues/3491) LocalProxy, HttpClient are kept alive in the root container (ServiceProvider), which causes a Memory Leak
* [#3481](https://github.com/MarimerLLC/csla/issues/3481) GraphMerge loses child objects
* [#3617](https://github.com/MarimerLLC/csla/issues/3617)Blazor ViewModel silently fails if model IsBusy
* [#3235](https://github.com/MarimerLLC/csla/issues/3235)HttpProxy throw System.NullReferenceException when cannot connected to server
* [#3616](https://github.com/MarimerLLC/csla/issues/3616)Optimize when rules cascade based on input properties
* [#3622](https://github.com/MarimerLLC/csla/issues/3662)Add WaitForIdle method to base types with IsBusy property
* [#3623](https://github.com/MarimerLLC/csla/issues/3623)Add client-side data portal cache capability
* [#3617](https://github.com/MarimerLLC/csla/issues/3617) Blazor ViewModel silently fails if model IsBusy
* [#3235](https://github.com/MarimerLLC/csla/issues/3235) HttpProxy throw System.NullReferenceException when cannot connected to server
* [#3616](https://github.com/MarimerLLC/csla/issues/3616) Optimize when rules cascade based on input properties
* [#3622](https://github.com/MarimerLLC/csla/issues/3662) Add WaitForIdle method to base types with IsBusy property
* [#3623](https://github.com/MarimerLLC/csla/issues/3623) Add client-side data portal cache capability
* [#3635](https://github.com/MarimerLLC/csla/issues/3635) Ensure IDataPortalCache interface works with async/await

* Numerous updates to dependencies

Expand All @@ -28,6 +29,7 @@ CSLA .NET version 8.0.0 adds support for .NET 8 and other enhancements.
* @Inmobilis
* @michaelcsikos
* mtavares628
* @ossendorf-at-hoelscher
* @rockfordlhotka
* @russblair
* @swegele
Expand Down

0 comments on commit 36f7672

Please sign in to comment.