ItemsCache.Refresh.Polling 1.0.0

dotnet add package ItemsCache.Refresh.Polling --version 1.0.0
                    
NuGet\Install-Package ItemsCache.Refresh.Polling -Version 1.0.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="ItemsCache.Refresh.Polling" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ItemsCache.Refresh.Polling" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ItemsCache.Refresh.Polling" />
                    
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 ItemsCache.Refresh.Polling --version 1.0.0
                    
#r "nuget: ItemsCache.Refresh.Polling, 1.0.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.
#:package ItemsCache.Refresh.Polling@1.0.0
                    
#: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=ItemsCache.Refresh.Polling&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ItemsCache.Refresh.Polling&version=1.0.0
                    
Install as a Cake Tool

ItemsCache

CI NuGet License: MIT

A high-performance, flexible caching library for ASP.NET Core applications that provides automatic data loading, background refresh, and retry logic with SOLID principles.

Features

  • 🚀 High Performance: Optimized for speed with minimal memory overhead
  • 🔄 Background Refresh: Automatic cache refresh with configurable intervals
  • 🛡️ Retry Logic: Built-in retry policies using Polly for resilient operations
  • 🏗️ SOLID Principles: Clean architecture with proper abstractions
  • 📦 Modular Design: Use only what you need with separate packages
  • 🔧 Easy Integration: Simple setup with dependency injection
  • 📊 Observability: Built-in logging and monitoring support

Packages

Package Description NuGet
ItemsCache.All Complete package with all features NuGet
ItemsCache Core caching functionality NuGet
ItemsCache.Refresh Background refresh capabilities NuGet
ItemsCache.Refresh.Polling Polling-based refresh implementation NuGet
ItemsCache.RetryPolicy Retry policy implementations with Polly NuGet

Quick Start

Installation

For the complete experience, install the main package:

dotnet add package ItemsCache.All

Or install individual packages based on your needs:

dotnet add package ItemsCache
dotnet add package ItemsCache.Refresh.Polling
dotnet add package ItemsCache.RetryPolicy

Basic Usage

  1. Register services in your Program.cs:
using ItemsCache.Extensions;

var builder = WebApplication.CreateBuilder(args);

// Add ItemsCache services
builder.Services.AddItemsCache()
    .AddRefreshPolling()
    .AddRetryPolicy();

var app = builder.Build();
  1. Create a data source:
public class ProductDataSource : IDataSource<Product>
{
    private readonly HttpClient _httpClient;
    
    public ProductDataSource(HttpClient httpClient)
    {
        _httpClient = httpClient;
    }
    
    public async Task<Product> LoadAsync(string key)
    {
        var response = await _httpClient.GetFromJsonAsync<Product>($"/api/products/{key}");
        return response ?? throw new InvalidOperationException("Product not found");
    }
}
  1. Use the cache service:
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly IItemsCacheService<Product> _cache;
    
    public ProductsController(IItemsCacheService<Product> cache)
    {
        _cache = cache;
    }
    
    [HttpGet("{id}")]
    public async Task<ActionResult<Product>> GetProduct(string id)
    {
        var product = await _cache.GetAsync(id);
        return Ok(product);
    }
}

Advanced Configuration

Background Refresh

Configure automatic cache refresh:

builder.Services.AddItemsCache()
    .AddRefreshPolling(options =>
    {
        options.RefreshInterval = TimeSpan.FromMinutes(5);
        options.Enabled = true;
    });

Retry Policies

Configure retry behavior:

builder.Services.AddItemsCache()
    .AddRetryPolicy(options =>
    {
        options.MaxRetryAttempts = 3;
        options.DelayBetweenRetries = TimeSpan.FromSeconds(1);
        options.UseExponentialBackoff = true;
    });

Custom Data Sources

Implement your own data source:

public class DatabaseDataSource : IDataSource<User>
{
    private readonly AppDbContext _context;
    
    public DatabaseDataSource(AppDbContext context)
    {
        _context = context;
    }
    
    public async Task<User> LoadAsync(string key)
    {
        var user = await _context.Users.FindAsync(key);
        return user ?? throw new InvalidOperationException("User not found");
    }
}

Architecture

ItemsCache follows SOLID principles with a clean, modular architecture:

ItemsCache.Core.Abstraction
├── IDataSource<T>
├── IItemsCacheService<T>
└── IItemsCacheServiceWithModifications<T>

ItemsCache.Core
├── ItemsCacheService<T>
├── ItemsCacheLoader<T>
└── CacheInitHostedService

ItemsCache.Refresh.Abstraction
├── IRefreshItemCacheHandler<T>
└── IRefreshItemCacheHandlerFactory<T>

ItemsCache.Refresh.Core
├── RefreshItemCacheHandler<T>
└── RefreshItemCacheHandlerFactory<T>

ItemsCache.Refresh.Polling
├── PollingRefreshService<T>
└── PollingRefreshHostedService<T>

ItemsCache.RetryPolicy.Abstraction
├── IRetryPolicy<T>
└── RetryPolicyOptions<T>

ItemsCache.RetryPolicy.Polly
└── PollyRetryPolicy<T>

Performance Considerations

  • Memory Efficient: Uses weak references and proper disposal patterns
  • Thread Safe: All operations are thread-safe and optimized for concurrent access
  • Lazy Loading: Data is loaded only when needed
  • Background Processing: Refresh operations don't block main thread
  • Configurable Limits: Set memory and performance limits as needed

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

Development Setup

  1. Clone the repository
  2. Install .NET 9.0 SDK
  3. Run dotnet restore
  4. Run dotnet build
  5. Run dotnet test

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

Changelog

See CHANGELOG.md for a list of changes and version history.


Made with ❤️ by the ItemsCache Contributors

Product Compatible and additional computed target framework versions.
.NET 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. 
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 ItemsCache.Refresh.Polling:

Package Downloads
ItemsCache.All

Complete ItemsCache package with all features - includes core caching, background refresh, polling, and retry policies. Perfect for getting started quickly.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 116 10/28/2025
0.0.1-preview.5 110 10/28/2025