Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,33 @@ 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,
// // total count of cache items, default value is 10000
// 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")
Expand Down
2 changes: 1 addition & 1 deletion ToDoList.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- [x] GetCount
- [x] Flush/FlushAsync
- [x] TrySet/TrySetAsync
- [ ] GetExpiration/GetExpirationAsync
- [x] GetExpiration/GetExpirationAsync
- [ ] Others...

## Serializer Extensions
Expand Down
32 changes: 27 additions & 5 deletions docs/AspectCore.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -66,21 +84,25 @@ public class DemoService : IDemoService
```csharp
public class Startup
{
//others...
// others...

public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDemoService, DemoService>();

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";
});
}
}
```
Expand Down
5 changes: 3 additions & 2 deletions docs/CSRedis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
45 changes: 33 additions & 12 deletions docs/Castle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
});
}
}
```
Expand Down
1 change: 1 addition & 0 deletions docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/In-Memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/Redis.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down