/* * Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Plugins.Extensions.VNCache * File: IEntityCache.cs * * IEntityCache.cs is part of VNLib.Plugins.Extensions.VNCache * which is part of the larger VNLib collection of libraries and utilities. * * VNLib.Plugins.Extensions.VNCache is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * VNLib.Plugins.Extensions.VNCache is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see https://www.gnu.org/licenses/. */ using System.Threading; using System.Threading.Tasks; namespace VNLib.Plugins.Extensions.VNCache.DataModel { /// /// Represents a cache that stores referrence type entities /// /// The referrence entity type public interface IEntityCache where T : class { /// /// Gets an entity from the cache by its id. Returns null if the entity is not found /// /// The id of the entity to retrieve from the store /// A token to cancel the operation /// The entity if found, null otherwise Task GetAsync(string id, CancellationToken token = default); /// /// Upserts an entity into the cache by its id. This updates an existing entity /// or inserts a new one. /// /// The id of the entity to update /// A referrence to the entity instance to update /// A token to cancel the operation /// A task that completes when the update has completed successfully Task UpsertAsync(string id, T entity, CancellationToken token = default); /// /// Removes an entity from the cache by its id /// /// The id of the item to remove /// A token to cancel delete opdation /// A task that completes when the item has been deleted successfully Task RemoveAsync(string id, CancellationToken token = default); } }