From a341819711cda358652ad84b1e507d9559ecabfd Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Apr 2021 18:22:57 +0800 Subject: refactor: Refactor data services. --- BackEnd/Timeline/Services/Data/IDataManager.cs | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 BackEnd/Timeline/Services/Data/IDataManager.cs (limited to 'BackEnd/Timeline/Services/Data/IDataManager.cs') 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 +{ + /// + /// A data manager controlling data. + /// + /// + /// 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. + /// + public interface IDataManager + { + /// + /// Saves the data to a new entry if it does not exist, + /// increases its ref count and returns a tag to the entry. + /// + /// The data. Can't be null. + /// Cancellation token. + /// The tag of the created entry. + /// Thrown when is null. + public Task RetainEntry(byte[] data, CancellationToken cancellationToken = default); + + /// + /// Decrease the the ref count of the entry. + /// Remove it if ref count is zero. + /// + /// The tag of the entry. + /// Cancellation token. + /// Thrown when is null. + /// + /// It's no-op if entry with tag does not exist. + /// + public Task FreeEntry(string tag, CancellationToken cancellationToken = default); + + /// + /// Retrieve the entry with given tag. If not exist, returns null. + /// + /// The tag of the entry. + /// Cancellation token. + /// The data of the entry. If not exist, returns null. + /// Thrown when is null. + public Task GetEntry(string tag, CancellationToken cancellationToken = default); + } +} -- cgit v1.2.3