aboutsummaryrefslogtreecommitdiff
path: root/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs')
-rw-r--r--lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs43
1 files changed, 35 insertions, 8 deletions
diff --git a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs
index 8a857d4..18c8a98 100644
--- a/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs
+++ b/lib/VNLib.Data.Caching/src/IGlobalCacheProvider.cs
@@ -22,11 +22,30 @@
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
+using System;
using System.Threading;
using System.Threading.Tasks;
namespace VNLib.Data.Caching
{
+
+ /// <summary>
+ /// A delegate method that will set the raw object data on the state object
+ /// if data was found
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="state">The state passed to the original call</param>
+ /// <param name="objectData">The raw data of the cached object</param>
+ public delegate void ObjectDataSet<T>(T state, ReadOnlySpan<byte> objectData);
+
+ /// <summary>
+ /// A delegate method that will get the raw objet data from a state object
+ /// </summary>
+ /// <typeparam name="T"></typeparam>
+ /// <param name="state">The state object passed to the caller</param>
+ /// <returns>The raw object data to store in cache</returns>
+ public delegate ReadOnlySpan<byte> ObjectDataReader<T>(T state);
+
/// <summary>
/// A global cache provider interface
/// </summary>
@@ -38,6 +57,12 @@ namespace VNLib.Data.Caching
bool IsConnected { get; }
/// <summary>
+ /// Gets the underlying cache store object
+ /// </summary>
+ /// <returns>The underlying cache store instance</returns>
+ object GetUnderlyingStore();
+
+ /// <summary>
/// Asynchronously gets a value from the backing cache store
/// </summary>
/// <typeparam name="T"></typeparam>
@@ -63,7 +88,7 @@ namespace VNLib.Data.Caching
/// <param name="key">The key identifying the item to delete</param>
/// <param name="cancellation">A token to cancel the async operation</param>
/// <returns>A task that completes when the delete operation has compelted</returns>
- Task DeleteAsync(string key, CancellationToken cancellation);
+ Task<bool> DeleteAsync(string key, CancellationToken cancellation);
/// <summary>
/// Asynchronously gets a value from the backing cache store
@@ -73,7 +98,7 @@ namespace VNLib.Data.Caching
/// <param name="deserializer">The specific deserialzer to deserialze the object</param>
/// <param name="cancellation">A token to cancel the async operation</param>
/// <returns>The value if found, or null if it does not exist in the store</returns>
- Task<T?> GetAsync<T>(string key, ICacheObjectDeserialzer deserializer, CancellationToken cancellation);
+ Task<T?> GetAsync<T>(string key, ICacheObjectDeserializer deserializer, CancellationToken cancellation);
/// <summary>
/// Asynchronously sets (or updates) a cached value in the backing cache store
@@ -83,19 +108,20 @@ namespace VNLib.Data.Caching
/// <param name="newKey">An optional key that will be changed for the new object</param>
/// <param name="cancellation">A token to cancel the async operation</param>
/// <param name="value">The value to set at the given key</param>
- /// <param name="serialzer">The <see cref="ICacheObjectSerialzer"/> used to serialze the entity</param>
+ /// <param name="serialzer">The <see cref="ICacheObjectSerializer"/> used to serialze the entity</param>
/// <returns>A task that completes when the update operation has compelted</returns>
- Task AddOrUpdateAsync<T>(string key, string? newKey, T value, ICacheObjectSerialzer serialzer, CancellationToken cancellation);
+ Task AddOrUpdateAsync<T>(string key, string? newKey, T value, ICacheObjectSerializer serialzer, CancellationToken cancellation);
/// <summary>
/// Asynchronously gets a value from the backing cache store and writes it to the
/// supplied data buffer
/// </summary>
/// <param name="key">The key identifying the object to recover from cache</param>
- /// <param name="rawData">The </param>
+ /// <param name="callback">The callback method that will get the raw object data</param>
+ /// <param name="state">The state parameter to pass to the callback when invoked</param>
/// <param name="cancellation">A token to cancel the async operation</param>
/// <returns>A task that complets when the object data has been written to the data buffer</returns>
- Task GetAsync(string key, IObjectData rawData, CancellationToken cancellation);
+ Task GetAsync<T>(string key, ObjectDataSet<T> callback, T state, CancellationToken cancellation);
/// <summary>
/// Asynchronously sets (or updates) a cached value in the backing cache store
@@ -103,9 +129,10 @@ namespace VNLib.Data.Caching
/// </summary>
/// <param name="key">The key identifying the object to recover from cache</param>
/// <param name="newKey">An optional key that will be changed for the new object</param>
+ /// <param name="callback">A callback method that will set the raw object data when received</param>
+ /// <param name="state">The callback state parameter</param>
/// <param name="cancellation">A token to cancel the async operation</param>
- /// <param name="rawData">The raw data to store at the given key</param>
/// <returns>A task that completes when the update operation has compelted</returns>
- Task AddOrUpdateAsync(string key, string? newKey, IObjectData rawData, CancellationToken cancellation);
+ Task AddOrUpdateAsync<T>(string key, string? newKey, ObjectDataReader<T> callback, T state, CancellationToken cancellation);
}
} \ No newline at end of file