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
<PackageReference Include="ItemsCache.Refresh.Polling" Version="1.0.0" />
<PackageVersion Include="ItemsCache.Refresh.Polling" Version="1.0.0" />
<PackageReference Include="ItemsCache.Refresh.Polling" />
paket add ItemsCache.Refresh.Polling --version 1.0.0
#r "nuget: ItemsCache.Refresh.Polling, 1.0.0"
#:package ItemsCache.Refresh.Polling@1.0.0
#addin nuget:?package=ItemsCache.Refresh.Polling&version=1.0.0
#tool nuget:?package=ItemsCache.Refresh.Polling&version=1.0.0
ItemsCache
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
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
- 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();
- 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");
}
}
- 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
- Clone the repository
- Install .NET 9.0 SDK
- Run
dotnet restore - Run
dotnet build - 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 | Versions 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. |
-
net9.0
- ItemsCache.Core.Abstraction (>= 1.0.0)
- ItemsCache.Refresh (>= 1.0.0)
- ItemsCache.Refresh.Abstraction (>= 1.0.0)
- ItemsCache.Refresh.Polling.Abstraction (>= 1.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.10)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.10)
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 |