ResponseCache is a .NET Core library designed to enhance the performance of web APIs by caching responses. It simplifies the process of implementing caching strategies, helping to reduce load times and improve scalability.
- Easy Integration: Seamlessly integrates with ASP.NET Core applications.
- Flexible Caching: Supports various caching strategies like in-memory, distributed, and more.
- Customizable: Easily configure cache duration, key generation, and eviction policies.
- Enhanced Performance: Reduces server load by serving cached responses for repeated requests.
- Minimal Setup: Simple to set up and use with minimal configuration.
- .NET Core 8.0 SDK
- Basic knowledge of ASP.NET Core
To install ResponseCache, add the package via NuGet Package Manager:
dotnet add package ResponseCache
Or edit your .csproj
file to include:
<PackageReference Include="ResponseCache" Version="1.0.0" />
-
Configure Services: Add the
ResponseCache
service in yourStartup.cs
orProgram.cs
:public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddResponseCaching(); // Add ResponseCaching service }
-
Apply Caching: Use the
[ResponseCache]
attribute on your controllers or actions:[ApiController] [Route("[controller]")] public class WeatherForecastController : ControllerBase { [HttpGet] [ResponseCache(Duration = 60)] // Cache response for 60 seconds public IEnumerable<WeatherForecast> Get() { // Your logic here } }
-
Advanced Configuration: Customize caching settings using the
ResponseCacheOptions
:public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddResponseCaching(options => { options.UseInMemoryCache = true; // Choose in-memory caching options.DefaultDuration = 120; // Default cache duration }); }
To run the unit tests, use the following command:
dotnet test
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature/YourFeature
). - Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
For any inquiries or issues, please open an issue on GitHub or contact me at [your email address].
Note: This project is still in development. Contributions and suggestions are highly appreciated!