Just.CacheIt 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Just.CacheIt --version 1.0.1                
NuGet\Install-Package Just.CacheIt -Version 1.0.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="Just.CacheIt" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Just.CacheIt --version 1.0.1                
#r "nuget: Just.CacheIt, 1.0.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.
// Install Just.CacheIt as a Cake Addin
#addin nuget:?package=Just.CacheIt&version=1.0.1

// Install Just.CacheIt as a Cake Tool
#tool nuget:?package=Just.CacheIt&version=1.0.1                

cache-it

Framework for Direct and Simple Update of Cache Components in .NET

Why Should I Use It?

If you want to use and refresh the cache in your application, it's a good choice to use it.

Since you only need to inherit our interface and call the dependency injection extension.

Usage

  1. Choose a component of your system that you want to have some type of information cached for quick access to data.
namespace MySuperApp.Services
{
    public class SuperRequestedService
    {
        ...
    }
}
  1. Inherit from the ICacheable interface and call your class functions that load or update your data as needed.
namespace MySuperApp.Services
{
    public class SuperRequestedService: ICacheable
    {
        ...

        public async Task Load()
        {
            await FillMySuperData();
        }

        public async Task Refresh()
        {
            await RefreshMySuperData();            
        }

    }
}

The Load Method is called once when your app starts. And the Refresh Method from time to time.

By default, the refresh time is 1 minute. See the Custom Configuration topic for more details.

  1. Call AddCacheIt Service Collection Extension.
public void ConfigureServices(IServiceCollection services)
{
    services.AddControllers();
    ...
    services.AddSingleton<SuperRequestedService>();
    ...
    services.AddCacheIt();
}
  1. Start your app and Voilá!

For simplicity the example class does not inherits from another interface but if your component/class does, there is no problem.

How It Works

The HostedService Handler, registered via AddCacheIt Service Collection Extension, retrieves by reflection any Type that Inherits from ICacheable.

It then uses the ServiceProvider to retrieve the registered services and then calls the Load method if it is an Application Start, and over the life of the application and the defined refresh interval it calls the Refresh method.

Custom Configuration

Whether your update needs to be more frequent or not, you can use a custom setting in the appsettings.json of your project.

See the example below, that we want to refresh at each 10 minutes.

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Debug"
    }
  },
  "AllowedHosts": "*",
  ...
  "CacheIt":{
    "RefreshIntervalMinutes":10
  }
  ...
}

Contributing

Open a branch, code and open a PR to main and request review for any of the Contributors. For now this is the main flow.

License

Licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.4 1,606 2/21/2023
2.1.4-preview 153 12/27/2022
2.1.3-preview 156 11/6/2022
1.1.3 1,337 7/18/2022
1.1.3-preview 224 6/19/2022
1.0.3 1,128 5/22/2022
1.0.3-preview 317 5/13/2022
1.0.2 399 12/6/2021
1.0.1 967 12/5/2021