GithubHelp home page GithubHelp logo

winntxp / easycaching Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dotnetcore/easycaching

0.0 1.0 0.0 1.92 MB

:boom: 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: MIT License

C# 99.44% Batchfile 0.56%

easycaching's Introduction

EasyCaching is a 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 China Foundation 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

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();
        
        //2. Redis Cache
        //services.AddDefaultRedisCache(option=>
        //{                
        //    option.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379));
        //    option.Password = "";
        //});
        
        //3. Memcached Cache
        //services.AddDefaultMemcached(option=>
        //{                
        //    option.AddServer("127.0.0.1",11211);        
        //});
        
        //4. SQLite Cache
        //services.AddSQLiteCache(option=>{});
    }
    
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        //3. 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));   
                
        //Remove
        _provider.Remove("demo");

        //Remove Async
        await _provider.RemoveAsync("demo");
           
        //Refresh
        _provider.Refresh("demo", "123", TimeSpan.FromMinutes(1));

        //Refresh Async
        await _provider.RefreshAsync("demo", "123", TimeSpan.FromMinutes(1)); 
        
        //RemoveByPrefix
        _provider.RemoveByPrefix("prefix");

        //RemoveByPrefixAsync
        await _provider.RemoveByPrefixAsync("prefix");

        //SetAll
        _provider.SetAll(new Dictionary<string, string>()
        {
            {"key:1","value1"},
            {"key:2","value2"}
        }, TimeSpan.FromMinutes(1));

        //SetAllAsync
        await _provider.SetAllAsync(new Dictionary<string, string>()
        {
            {"key:1","value1"},
            {"key:2","value2"}
        }, TimeSpan.FromMinutes(1));

        //GetAll
        var res = _provider.GetAll(new List<string> { "key:1", "key:2" });

        //GetAllAsync
        var res = await _provider.GetAllAsync(new List<string> { "key:1", "key:2" });
        
        //GetByPrefix
        var res = _provider.GetByPrefix<T>("prefix");
        
        //GetByPrefixAsync
        var res = await _provider.GetByPrefixAsync<T>("prefix");
        
        //RemoveAll
        _provider.RemoveAll(new List<string> { "key:1", "key:2" });

        //RemoveAllAsync
        awiat _provider.RemoveAllAsync(new List<string> { "key:1", "key:2" });
        
    }
}

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)
  • 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
  • Flush/FlushAsync(whether is in need ? )
  • 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

easycaching's People

Contributors

catcherwong avatar fossabot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.