diff --git a/README.md b/README.md index 0963906d..2d5fee62 100644 --- a/README.md +++ b/README.md @@ -62,15 +62,15 @@ public class Startup public void ConfigureServices(IServiceCollection services) { //configuration - services.AddEasyCaching(option=> + services.AddEasyCaching(options => { //use memory cache that named default - option.UseInMemory("default"); + options.UseInMemory("default"); // // use memory cache with your own configuration - // config.UseInMemory(options => + // options.UseInMemory(config => // { - // options.DBConfig = new InMemoryCachingOptions + // config.DBConfig = new InMemoryCachingOptions // { // // scan time, default value is 60s // ExpirationScanFrequency = 60, @@ -78,17 +78,17 @@ public class Startup // SizeLimit = 100 // }; // // the max random second will be added to cache's expiration, default value is 120 - // options.MaxRdSecond = 120; + // config.MaxRdSecond = 120; // // whether enable logging, default is false - // options.EnableLogging = false; + // config.EnableLogging = false; // // mutex key's alive time(ms), default is 5000 - // options.LockMs = 5000; + // config.LockMs = 5000; // // when mutex key alive, it will sleep some time, default is 300 - // options.SleepMs = 300; + // config.SleepMs = 300; // }, "m2"); //use redis cache that named redis1 - option.UseRedis(config => + options.UseRedis(config => { config.DBConfig.Endpoints.Add(new ServerEndPoint("127.0.0.1", 6379)); }, "redis1") diff --git a/ToDoList.md b/ToDoList.md index 42b01759..aa6dc5ee 100644 --- a/ToDoList.md +++ b/ToDoList.md @@ -26,7 +26,7 @@ - [x] GetCount - [x] Flush/FlushAsync - [x] TrySet/TrySetAsync -- [ ] GetExpiration/GetExpirationAsync +- [x] GetExpiration/GetExpirationAsync - [ ] Others... ## Serializer Extensions diff --git a/docs/AspectCore.md b/docs/AspectCore.md index 1b50d9e4..fb2a0848 100644 --- a/docs/AspectCore.md +++ b/docs/AspectCore.md @@ -15,18 +15,36 @@ Install-Package EasyCaching.Interceptor.AspectCore Install-Package EasyCaching.InMemory ``` + ## 2. Define services ### 2.1 Define the interface -This interface must inherit **IEasyCaching** by default. And we need to add `EasyCachingAble`,`EasyCachingPut` and `EasyCachingEvict` to the methods that we want to simplify the caching operation. +We need to add `EasyCachingAble`,`EasyCachingPut` or `EasyCachingEvict` on the methods that we want to simplify the caching operation. + +The following unordered list shows you what the attribute will affect the caching. - EasyCachingAble , Read from cached items - EasyCachingPut , Update the cached item - EasyCachingEvict , Remove one cached item or multi cached items +There are some properties that we should know + +Property | Description | Apply +---|---|--- +CacheKeyPrefix | To specify the prefix of your cache key | All +CacheProviderName | To specify which provider you want to use | All +IsHightAvailability | Whether caching opreation will break your method | All +Expiration | To specify the expiration of your cache item,the unit is second | EasyCachingAble and EasyCachingPut +IsAll | Whether remove all the cached items start with the CacheKeyPrefix | EasyCachingEvict only +IsBefore | Remove the cached item before method excute or after method excute | EasyCachingEvict only + +Here is a easy sample to show you how to use. + +Defining a regular interface at first. + ```csharp -public interface IDemoService : EasyCaching.Core.Internal.IEasyCaching +public interface IDemoService { [EasyCachingAble(Expiration = 10)] string GetCurrentUtcTime(); @@ -66,7 +84,7 @@ public class DemoService : IDemoService ```csharp public class Startup { - //others... + // others... public IServiceProvider ConfigureServices(IServiceCollection services) { @@ -74,13 +92,17 @@ public class Startup services.AddEasyCaching(option=> { - //use memory cache + // use memory cache option.UseInMemory("default"); }); services.AddMvc(); - return services.ConfigureAspectCoreInterceptor(); + return services.ConfigureAspectCoreInterceptor(options => + { + // Specify which provider you want to use + options.CacheProviderName = "default"; + }); } } ``` diff --git a/docs/CSRedis.md b/docs/CSRedis.md index dc86bcdc..913e179f 100644 --- a/docs/CSRedis.md +++ b/docs/CSRedis.md @@ -72,9 +72,10 @@ And what we add in `appsettings.json` are as following: ```JSON "easycaching": { "csredis": { - "CachingProviderType": 2, "MaxRdSecond": 120, - "Order": 2, + "EnableLogging": false, + "LockMs": 5000, + "SleepMs": 300, "dbconfig": { "ConnectionStrings":[ "127.0.0.1:6388,defaultDatabase=13,poolsize=10" diff --git a/docs/Castle.md b/docs/Castle.md index 3075ac79..83c82d94 100644 --- a/docs/Castle.md +++ b/docs/Castle.md @@ -20,41 +20,58 @@ Install-Package EasyCaching.InMemory ### 2.1 Define the interface -Just define a regular interface. +We need to add `EasyCachingAble`,`EasyCachingPut` or `EasyCachingEvict` on the methods that we want to simplify the caching operation. + +The following unordered list shows you what the attribute will affect the caching. + +- EasyCachingAble , Read from cached items +- EasyCachingPut , Update the cached item +- EasyCachingEvict , Remove one cached item or multi cached items + +There are some properties that we should know + +Property | Description | Apply +---|---|--- +CacheKeyPrefix | To specify the prefix of your cache key | All +CacheProviderName | To specify which provider you want to use | All +IsHightAvailability | Whether caching opreation will break your method | All +Expiration | To specify the expiration of your cache item,the unit is second | EasyCachingAble and EasyCachingPut +IsAll | Whether remove all the cached items start with the CacheKeyPrefix | EasyCachingEvict only +IsBefore | Remove the cached item before method excute or after method excute | EasyCachingEvict only + +Here is a easy sample to show you how to use. + +Defining a regular interface at first. ```csharp public interface IDemoService { + [EasyCachingAble(Expiration = 10)] string GetCurrentUtcTime(); + [EasyCachingPut(CacheKeyPrefix = "Castle")] string PutSomething(string str); + [EasyCachingEvict(IsBefore = true)] void DeleteSomething(int id); } ``` -This implement must inherit **IEasyCaching** by default. And we need to add `EasyCachingAble`,`EasyCachingPut` and `EasyCachingEvict` to the methods that we want to simplify the caching operation. - -- EasyCachingAble , Read from cached items -- EasyCachingPut , Update the cached item -- EasyCachingEvict , Remove one cached item or multi cached items +Just implement the above interface. ```csharp -public class DemoService : IDemoService , IEasyCaching +public class DemoService : IDemoService { - [EasyCachingEvict(IsBefore = true)] public void DeleteSomething(int id) { System.Console.WriteLine("Handle delete something.."); } - [EasyCachingAble(Expiration = 10)] public string GetCurrentUtcTime() { return System.DateTime.UtcNow.ToString(); } - [EasyCachingPut(CacheKeyPrefix = "Castle")] public string PutSomething(string str) { return str; @@ -75,13 +92,17 @@ public class Startup services.AddEasyCaching(option => { - //use memory cache + // use memory cache option.UseInMemory("default"); }); services.AddMvc(); - return services.ConfigureCastleInterceptor(); + return services.ConfigureCastleInterceptor(options => + { + // Specify which provider you want to use + options.CacheProviderName = "default"; + }); } } ``` diff --git a/docs/Features.md b/docs/Features.md index e5cce68f..ea2f3627 100644 --- a/docs/Features.md +++ b/docs/Features.md @@ -14,6 +14,7 @@ 11. GetCount 12. Flush/FlushAsync 13. TrySet/TrySetAsync + 14. GetExpiration/GetExpirationAsync - Caching Providers(Both local caching and distributed caching) 1. In-Memory 2. Memcached diff --git a/docs/In-Memory.md b/docs/In-Memory.md index 9894137e..ba98c7f3 100644 --- a/docs/In-Memory.md +++ b/docs/In-Memory.md @@ -83,9 +83,10 @@ And what we add in `appsettings.json` are as following: ```JSON "easycaching": { "inmemory": { - "CachingProviderType": 1, "MaxRdSecond": 120, - "Order": 2, + "EnableLogging": false, + "LockMs": 5000, + "SleepMs": 300, "DBConfig":{ "SizeLimit": 10000, "ExpirationScanFrequency": 60 diff --git a/docs/Redis.md b/docs/Redis.md index caa2185d..fa5ef5e1 100644 --- a/docs/Redis.md +++ b/docs/Redis.md @@ -66,9 +66,10 @@ And what we add in `appsettings.json` are as following: ```JSON "easycaching": { "redis": { - "CachingProviderType": 2, "MaxRdSecond": 120, - "Order": 2, + "EnableLogging": false, + "LockMs": 5000, + "SleepMs": 300, "dbconfig": { "Password": null, "IsSsl": false,