diff options
author | crupest <crupest@outlook.com> | 2021-04-27 18:22:57 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-04-27 18:22:57 +0800 |
commit | deb02d10e6139bb74a63343e2a8b70fee11bec22 (patch) | |
tree | 160b7a2691786bfad8decbeeabe5fa1e09a876f3 /BackEnd/Timeline/Services/Data/IDataManager.cs | |
parent | 956306bf47db6495386945c2dbfe623cf48b185a (diff) | |
download | timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.tar.gz timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.tar.bz2 timeline-deb02d10e6139bb74a63343e2a8b70fee11bec22.zip |
refactor: Refactor data services.
Diffstat (limited to 'BackEnd/Timeline/Services/Data/IDataManager.cs')
-rw-r--r-- | BackEnd/Timeline/Services/Data/IDataManager.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/BackEnd/Timeline/Services/Data/IDataManager.cs b/BackEnd/Timeline/Services/Data/IDataManager.cs new file mode 100644 index 00000000..6a87c1b2 --- /dev/null +++ b/BackEnd/Timeline/Services/Data/IDataManager.cs @@ -0,0 +1,49 @@ +using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Timeline.Services.Data
+{
+ /// <summary>
+ /// A data manager controlling data.
+ /// </summary>
+ /// <remarks>
+ /// Identical data will be saved as one copy and return the same tag.
+ /// Every data has a ref count. When data is retained, ref count increase.
+ /// When data is freed, ref count decease. If ref count is decreased
+ /// to 0, the data entry will be destroyed and no longer occupy space.
+ /// </remarks>
+ public interface IDataManager
+ {
+ /// <summary>
+ /// Saves the data to a new entry if it does not exist,
+ /// increases its ref count and returns a tag to the entry.
+ /// </summary>
+ /// <param name="data">The data. Can't be null.</param>
+ /// <param name="cancellationToken">Cancellation token.</param>
+ /// <returns>The tag of the created entry.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="data"/> is null.</exception>
+ public Task<string> RetainEntry(byte[] data, CancellationToken cancellationToken = default);
+
+ /// <summary>
+ /// Decrease the the ref count of the entry.
+ /// Remove it if ref count is zero.
+ /// </summary>
+ /// <param name="tag">The tag of the entry.</param>
+ /// <param name="cancellationToken">Cancellation token.</param>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="tag"/> is null.</exception>
+ /// <remarks>
+ /// It's no-op if entry with tag does not exist.
+ /// </remarks>
+ public Task FreeEntry(string tag, CancellationToken cancellationToken = default);
+
+ /// <summary>
+ /// Retrieve the entry with given tag. If not exist, returns null.
+ /// </summary>
+ /// <param name="tag">The tag of the entry.</param>
+ /// <param name="cancellationToken">Cancellation token.</param>
+ /// <returns>The data of the entry. If not exist, returns null.</returns>
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="tag"/> is null.</exception>
+ public Task<byte[]?> GetEntry(string tag, CancellationToken cancellationToken = default);
+ }
+}
|