CacheBox 1.0.3

dotnet add package CacheBox --version 1.0.3                
NuGet\Install-Package CacheBox -Version 1.0.3                
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="CacheBox" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CacheBox --version 1.0.3                
#r "nuget: CacheBox, 1.0.3"                
#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 CacheBox as a Cake Addin
#addin nuget:?package=CacheBox&version=1.0.3

// Install CacheBox as a Cake Tool
#tool nuget:?package=CacheBox&version=1.0.3                

CacheBox

CacheBox is a lightweight and flexible caching solution designed for .NET applications. It provides an abstraction over multiple cache providers, allowing you to seamlessly switch between different caching providers while maintaining a consistent API.

Features

  • Pluggable Cache Providers: Use multiple cache backends like in-memory, Redis, or distributed caches with ease.
  • Dependency Injection Support: Integrate CacheBox seamlessly into your .NET Core projects using dependency injection.
  • High Performance: Optimized for minimal overhead.

Installation

To install CacheBox in your project, you can use the following NuGet command for your provider:

dotnet add package CacheBox.LiteDb
dotnet add package CacheBox.Memory
dotnet add package CacheBox.Redis
dotnet add package CacheBox.Sqlite

Usage

Basic Setup

  1. Configuration

    CacheBox uses a very simple configuration for all providers with 3 lines.

    "Cache": {
      // Optional: Global prefix to prepend to all keys.  Useful for shared systems.
      "AppPrefix": "MyApplication",
      // Connection string to connect to the provider.  See examples and links below for individual providers.
      "ConnectionString": "MyConnectionString",
      // Optional: Default TTL of the stored items.  This is a string representation interpreted by TimeSpan.TryParse().
      "Timeout": "0:10:0"
    },
    

    See the Microsoft Documentation for examples of time strings.

  2. Register CacheBox in your DI Container

    using CacheBox;
    
     public class Startup
     {
         public void ConfigureServices(IServiceCollection services)
         {
             services.AddCacheProvider<MemoryCacheProvider>(); // Example using in-memory cache
         }
     }
    
  3. Use CacheBox in your application

    public class MyService
     {
         private readonly ICacheProvider _cache;
    
         public MyService(ICacheProvider cache)
         {
             _cache = cache;
         }
    
         public async Task DoWorkAsync()
         {
             string data = await _cache.GetAsync("myKey", nameof(MyService));
            MyClass stronglyTyped = await _cache.GetAsync<MyClass>("myOtherKey", nameof(MyService));
         }
     }
    

Switching Providers

To switch cache providers, simply register the desired provider in ConfigureServices:

services.AddCacheProvider<RedisCacheProvider>();

Cache Providers

CacheBox supports multiple cache providers. Each provider can be installed as a separate NuGet package:

  • LiteDbCacheProvider: Uses LiteDb as the cache backing.

    Example connection string: Filename=D:\\cache.db;Password=MyPassword;Connection=shared

    See here for documentation.

    Note: You must use a shared connection for a distributed cache, otherwise the first service to connect will create a lock.

  • MemoryCacheProvider: A simple in-memory cache.

    A connection string is not needed for in-memory caching.

  • RedisCacheProvider: Uses Redis as the cache backing.

    Example connection string: myRedisServer:6379,password=MyPassword

    See here for documentation.

  • SqliteCacheProvider: Uses Sqlite as the cache backing.

    Example connection string: Data Source=Cache.db;Password=MyPassword

    See here for documentation.

Adding Custom Providers

You can also implement your own custom cache provider by creating a class that implements the ICacheProvider interface.

public class MyCustomCacheProvider : ICacheProvider
{
    // Implementation goes here
}

License

CacheBox is licensed under the GPL License. See the LICENSE for more information.

Contributing

Contributions are always welcome! Feel free to open an issue or submit a pull request.

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 is compatible.  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.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on CacheBox:

Package Downloads
CacheBox.LiteDb

Implementation of ICacheProvider used for adding LiteDb caching service to applications

CacheBox.Redis

Implementation of ICacheProvider used for adding Redis caching service to applications

CacheBox.Memory

Implementation of ICacheProvider used for adding In Memory caching service to applications

CacheBox.Sqlite

Implementation of ICacheProvider used for adding Sqlite caching service to applications

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 140 9/23/2024
1.0.2 133 9/22/2024
1.0.1 158 9/21/2024