Net.Cache 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Net.Cache --version 1.1.0
NuGet\Install-Package Net.Cache -Version 1.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net.Cache" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Net.Cache --version 1.1.0
#r "nuget: Net.Cache, 1.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Net.Cache as a Cake Addin
#addin nuget:?package=Net.Cache&version=1.1.0

// Install Net.Cache as a Cake Tool
#tool nuget:?package=Net.Cache&version=1.1.0

Net.Cache

Overview

Net.Cache is a comprehensive caching library for .NET, designed to offer versatile tools for cache management. The library focuses on facilitating key-value based caching operations and provides a default implementation with InMemoryStorageProvider. It allows for easy integration and extension, enabling developers to use different caching strategies while maintaining a consistent interface.

Features

  • Generic Caching Mechanism: Supports any data type for keys and values, requiring keys to be equatable and non-nullable.
  • Default In-Memory Caching: Includes InMemoryStorageProvider for out-of-the-box in-memory caching.
  • Customizable Storage Providers: Easily extend or implement custom storage providers to suit various caching needs.
  • Safe Value Retrieval: Utilize TryGetValue for safe retrieval, reducing the risk of exceptions with missing keys.
  • Dynamic Cache Management: Efficiently handle caching with the ability to dynamically add values when not present.

Getting Started

Installation

Install Net.Cache via the NuGet package manager or clone the repository into your project.

Usage

Implementing Custom Storage Providers

Create custom storage providers by implementing the IStorageProvider<TKey, TValue> interface. Alternatively, use the provided InMemoryStorageProvider<TKey, TValue>.

var inMemoryStorage = new InMemoryStorageProvider<int, string>();
Using CacheProvider

Manage your caching logic with CacheProvider<TKey, TValue>, which can handle multiple storage providers including custom ones.

var cache = new CacheProvider<int, string>(inMemoryStorage);
Storing and Retrieving Values

Easily store and retrieve values using keys.

// Storing a value
cache.Store(1, "Hello World");

// Retrieving a value
if (cache.TryGetValue(1, out var value)) {
    Console.WriteLine(value); // Outputs: Hello World
}
Adding Values Dynamically

Leverage the GetOrAdd method to add values to the cache dynamically if they don't already exist.

string value = cache.GetOrAdd(2, () => "New Value");
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Net.Cache:

Package Downloads
Net.Cache.DynamoDb

Net.Cache.DynamoDb is a specialized extension of the Net.Cache library, providing an abstract base class for DynamoDB storage providers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.2 343 5/17/2024
1.3.1 171 3/20/2024
1.3.0 538 3/19/2024
1.1.0 784 1/15/2024
1.0.0 273 12/4/2023

- CacheProvider working with collection of StorageProviders
- CacheProvider receive valueFactory function as method parameter
- Created InMemoryStorageProvider

Full changes can found here: https://github.com/The-Poolz/Net.Cache/releases/tag/v1.1.0