namespace DysonNetwork.Shared.Cache; public interface ICacheService { /// /// Sets a value in the cache with an optional expiration time /// Task SetAsync(string key, T value, TimeSpan? expiry = null); /// /// Gets a value from the cache /// Task GetAsync(string key); /// /// Get a value from the cache with the found status /// Task<(bool found, T? value)> GetAsyncWithStatus(string key); /// /// Removes a specific key from the cache /// Task RemoveAsync(string key); /// /// Adds a key to a group for group-based operations /// Task AddToGroupAsync(string key, string group); /// /// Removes all keys associated with a specific group /// Task RemoveGroupAsync(string group); /// /// Gets all keys belonging to a specific group /// Task> GetGroupKeysAsync(string group); /// /// Helper method to set a value in cache and associate it with multiple groups in one operation /// /// The type of value being cached /// Cache key /// The value to cache /// Optional collection of group names to associate the key with /// Optional expiration time for the cached item /// True if the set operation was successful Task SetWithGroupsAsync(string key, T value, IEnumerable? groups = null, TimeSpan? expiry = null); /// /// Acquires a distributed lock on the specified resource /// /// The resource identifier to lock /// How long the lock should be held before automatically expiring /// How long to wait for the lock before giving up /// How often to retry acquiring the lock during the wait time /// A distributed lock instance if acquired, null otherwise Task AcquireLockAsync(string resource, TimeSpan expiry, TimeSpan? waitTime = null, TimeSpan? retryInterval = null); /// /// Executes an action with a distributed lock, ensuring the lock is properly released afterwards /// /// The resource identifier to lock /// The action to execute while holding the lock /// How long the lock should be held before automatically expiring /// How long to wait for the lock before giving up /// How often to retry acquiring the lock during the wait time /// True if the lock was acquired and the action was executed, false otherwise Task ExecuteWithLockAsync(string resource, Func action, TimeSpan expiry, TimeSpan? waitTime = null, TimeSpan? retryInterval = null); /// /// Executes a function with a distributed lock, ensuring the lock is properly released afterwards /// /// The return type of the function /// The resource identifier to lock /// The function to execute while holding the lock /// How long the lock should be held before automatically expiring /// How long to wait for the lock before giving up /// How often to retry acquiring the lock during the wait time /// The result of the function if the lock was acquired, default(T) otherwise Task<(bool Acquired, T? Result)> ExecuteWithLockAsync(string resource, Func> func, TimeSpan expiry, TimeSpan? waitTime = null, TimeSpan? retryInterval = null); }