Cachula 0.1.0-beta.1

This is a prerelease version of Cachula.
dotnet add package Cachula --version 0.1.0-beta.1
                    
NuGet\Install-Package Cachula -Version 0.1.0-beta.1
                    
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="Cachula" Version="0.1.0-beta.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Cachula" Version="0.1.0-beta.1" />
                    
Directory.Packages.props
<PackageReference Include="Cachula" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Cachula --version 0.1.0-beta.1
                    
#r "nuget: Cachula, 0.1.0-beta.1"
                    
#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.
#:package Cachula@0.1.0-beta.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Cachula&version=0.1.0-beta.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Cachula&version=0.1.0-beta.1&prerelease
                    
Install as a Cake Tool

<div align="center">

Cachula logo

Cachula

</div>

<div align="center">

Build NuGet NuGet Downloads License

</div>

Cachula is a flexible, multi-layer caching library for .NET, designed for modern distributed applications. It supports in-memory and distributed cache layers, cache stampede protection, and seamless integration with dependency injection. Cachula is inspired by the best practices of modern caching libraries, with a special focus on efficient bulk operations.


Key Features

  • Multi-layer caching: Compose multiple cache layers (e.g., memory, Redis).
  • Bulk operations: Native support for efficient batch get/set/remove operations for multiple keys.
  • Cache stampede protection: Prevents multiple concurrent loads for the same key(s) using single-flight logic.
  • Null/miss handling: Distinguishes between cache misses and null values.
  • Dependency injection ready: Easy to add to your DI container.
  • Extensible: Plug in your own cache layers or stampede protection strategies.

Why Cachula?

Cachula is designed for high-throughput, data-driven .NET applications that need to:

  • Minimize round-trips to slow data sources.
  • Efficiently cache and retrieve large numbers of items at once.
  • Avoid cache stampede.
  • Compose multiple cache layers for optimal performance and reliability.

Unique advantage: Unlike most caching libraries, Cachula natively supports working with multiple keys at once, making it ideal for batch-oriented scenarios.


Quick Start

1. Register Cachula in DI

services.AddMemoryCache();
services.PutOnCachula()
    .WithMemoryCache(); // Adds in-memory cache layer

// Optionally add a distributed cache layer (e.g., Redis)
services.WithDistributedCache(new CachulaRedisCache(redisDatabase));

2. Use ICachulaCache in your services

public class MyService
{
    private readonly ICachulaCache _cache;
    public MyService(ICachulaCache cache) => _cache = cache;

    public async Task<MyData?> GetDataAsync(string key)
    {
        return await _cache.GetOrSetAsync(
            key,
            async ct => await LoadFromDbAsync(key, ct),
            TimeSpan.FromMinutes(10)
        );
    }

    public async Task<IReadOnlyCollection<MyData>> GetManyAsync(IEnumerable<string> keys)
    {
        return await _cache.GetOrSetManyAsync(
            keys,
            async (missingKeys, ct) => await LoadManyFromDbAsync(missingKeys, ct),
            TimeSpan.FromMinutes(10)
        );
    }
}

Advanced Usage

Custom Cache Layers

Implement ICacheLayer to add your own cache backend.

Distributed Cache

Use CachulaRedisCache for Redis support:

var redisCache = new CachulaRedisCache(redisDatabase);
services.WithDistributedCache(redisCache);

Null and Miss Handling

  • Null: Value was found in cache and is null.
  • Missed: Value was not found in cache.

FAQ

Q: How is Cachula different from FusionCache or CacheTower?

  • Cachula is focused on batch/bulk operations and multi-layer composition, with a simple, extensible API.
  • It is designed for scenarios where you need to cache and retrieve many items at once efficiently.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Cachula:

Package Downloads
Cachula.Redis

Redis provider for Cachula: multi-layer caching with Redis backend, cache stampede protection, bulk ops and DI integration.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-beta.1 87 8/10/2025

Initial beta with netstandard2.0/net8.0/net9.0 targets.