Skip to content

💥 EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!

License

Notifications You must be signed in to change notification settings

JoakimOgren/EasyCaching

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!

Coverage Status Member project of .NET Core Community GitHub license FOSSA Status

CI Build Status

Platform Build Server Status
AppVeyor Windows Build status
Travis Linux/OSX Build Status

Nuget Packages

Core

Package Name Version Downloads
EasyCaching.Core

Provider

Package Name Version Downloads
EasyCaching.InMemory
EasyCaching.Redis
EasyCaching.Memcached
EasyCaching.SQLite
EasyCaching.HybridCache

Interceptor

Package Name Version Downloads
EasyCaching.Interceptor.Castle
EasyCaching.Interceptor.AspectCore

Serializer

Package Name Version Downloads
EasyCaching.Serialization.MessagePack
EasyCaching.Serialization.Json
EasyCaching.Serialization.Protobuf

Others

Package Name Version Downloads
EasyCaching.ResponseCaching

Basci Usages

Step 1 : Install the package

Choose one kinds of caching type that you needs and install it via Nuget.

Install-Package EasyCaching.InMemory
Install-Package EasyCaching.Redis
Install-Package EasyCaching.SQLite
Install-Package EasyCaching.Memcached

Step 2 : Config in your Startup class

Different types of caching hvae their own way to config.

Here are samples show you how to config.

public class Startup
{
    //...
    
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();

        //1. In-Memory Cache
        services.AddDefaultInMemoryCache();
        
        //Read from appsetting.json
        //services.AddDefaultInMemoryCache(Configuration);
        
        ////2. Important step for using Memcached Cache
        //services.AddDefaultMemcached(op =>
        //{
        //    op.DBConfig.AddServer("127.0.0.1", 11211);
        //});

        //services.AddDefaultMemcached(Configuration);

        //3. Important step for using Redis Cache
        //services.AddDefaultRedisCache(option =>
        //{
        //    option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
        //    option.DBConfig.Password = "";
        //});

        //services.AddDefaultRedisCache(Configuration);

        ////4. Important step for using SQLite Cache
        //services.AddSQLiteCache(option => 
        //{
        //    option.DBConfig = new SQLiteDBOptions { FileName="my.db" };
        //});

        //services.AddSQLiteCache(Configuration);

        ////5. Important step for using Hybrid Cache
        ////5.1. Local Cache
        //services.AddDefaultInMemoryCache(x=>
        //{
        //    x.Order = 1;
        //});
        ////5.2 Distributed Cache
        //services.AddDefaultRedisCache(option =>
        //{
        //    option.Order = 2;
        //    option.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
        //    option.DBConfig.Password = "";
        //});
        ////5.3 Hybrid
        //services.AddDefaultHybridCache();
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        //2. Memcache Cache
        //app.UseDefaultMemcached();
    
        //4. SQLite Cache
        //app.UseSQLiteCache();
    }
}

Step 3 : Write code in you controller

[Route("api/[controller]")]
public class ValuesController : Controller
{
    private readonly IEasyCachingProvider _provider;

    public ValuesController(IEasyCachingProvider provider)
    {
        this._provider = provider;
    }

    [HttpGet]
    public string Get()
    {
        //Set
        _provider.Set("demo", "123", TimeSpan.FromMinutes(1));
            
        //Set Async
        await _provider.SetAsync("demo", "123", TimeSpan.FromMinutes(1));   
        
        //Get without data retriever
        var res = _provider.Get<string>("demo");
        
        //Get without data retriever Async
        var res = await _provider.GetAsync<string>("demo");
        
        //Get
        var res = _provider.Get("demo", () => "456", TimeSpan.FromMinutes(1));
        
        //Get Async    
        var res = await _provider.GetAsync("demo",async () => await Task.FromResult("456"), TimeSpan.FromMinutes(1));   
                
        //others ....
    }
}

Documentation

For more helpful information about EasyCaching, please click here for EasyCaching's documentation.

Examples

See sample

Todo List

Caching Providers

  • Memory
  • Redis
  • SQLite
  • Memcached
  • Hybrid(Combine local caching and distributed caching)
  • Disk
  • Others...

Basic Caching API

  • Get/GetAsync(with data retriever)
  • Get/GetAsync(without data retriever)
  • Set/SetAsync
  • Remove/RemoveAsync
  • Refresh/RefreshAsync
  • RemoveByPrefix/RemoveByPrefixAsync
  • SetAll/SetAllAsync
  • GetAll/GetAllAsync
  • GetByPrefix/GetByPrefixAsync
  • RemoveAll/RemoveAllAsync
  • GetCount
  • Flush/FlushAsync
  • Others...

Serializer Extensions

  • BinaryFormatter
  • MessagePack
  • Json
  • ProtoBuf
  • Others...

Caching Interceptor

  • AspectCore
  • Castle
  • Others ..
  1. EasyCachingAble
  2. EasyCachingPut
  3. EasyCachingEvict

Note: Not support Hybird Caching provider yet.

Caching Bus

  • Redis
  • RabbitMQ

Others

  • Configuration
  • Caching Region
  • Caching Statistics
  • UI Manager
  • Logger
  • Caching Warm Up
  • ...

Contributing

Pull requests, issues and commentary!

License

FOSSA Status

About

💥 EasyCaching is an open source caching library that contains basic usages and some advanced usages of caching which can help us to handle caching more easier!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 99.6%
  • Batchfile 0.4%