/*
* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.ObjectCache
* File: IBlobCache.cs
*
* IBlobCache.cs is part of VNLib.Data.Caching.ObjectCache which is part of the larger
* VNLib collection of libraries and utilities.
*
* VNLib.Data.Caching.ObjectCache 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.Data.Caching.ObjectCache 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;
using System.Collections.Generic;
namespace VNLib.Data.Caching.ObjectCache
{
///
/// Represents a binary data cache store
///
public interface IBlobCache : IEnumerable>, IDisposable
{
///
/// The id of the bucket this memory cache belongs to
///
public uint BucketId { get; }
///
/// The memory manager used to create memory handles
///
ICacheEntryMemoryManager MemoryManager { get; }
///
/// Attempts to retreive the entry at the given id.
///
/// The id of the object to locate
/// The cache entry if found, default otherwise
/// True if the entry was assigned
bool TryGetValue(string objectId, out CacheEntry entry);
///
/// Attempts to relocate the entry in the table by its new id.
///
/// The original id of the entry to modify
/// The new id of the entry
/// The original entry if found, default otherwise
/// True if the item was located and successfully updated, false if the operation failed
bool TryChangeKey(string objectId, string newId, out CacheEntry entry);
///
/// Adds the entry to the table by the id
///
///
/// The entry to store in the table
void Add(string objectId, CacheEntry entry);
///
/// Attempts to remove the entry at the given id, and returns the
/// entry if located.
///
/// The id of the entry to remove
/// The entry if found, default otherwise
/// True if the entry existed in the store, false otherwise
///
/// NOTE: If the return value is true, the store no longer maintains the lifetime
/// of the returned . You must manually dispose the entry
/// to avoid memory leaks.
///
bool Remove(string objectId, out CacheEntry entry);
///
/// Attempts to remove the entry at the given id, and release its memory.
///
/// The id of the entry to remove
/// True if the entry was found and disposed
bool Remove(string objectId);
}
}