https://github.com/zeelyn/aopcaching
A aop cache library, No code intrusion on the cached method. Support memory and redis,redis support partition. And support bloom filter.
https://github.com/zeelyn/aopcaching
Last synced: about 1 month ago
JSON representation
A aop cache library, No code intrusion on the cached method. Support memory and redis,redis support partition. And support bloom filter.
- Host: GitHub
- URL: https://github.com/zeelyn/aopcaching
- Owner: ZeeLyn
- Created: 2018-12-05T03:29:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-14T06:33:00.000Z (over 6 years ago)
- Last Synced: 2025-05-07T21:05:10.569Z (about 1 month ago)
- Language: C#
- Homepage:
- Size: 77.1 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# AopCaching
A aop cache library, No code intrusion on the cached method. Support memory and redis,redis support partition. And support bloom filter.# Note
The proxy method must be a virtual method or an interface.# Packages & Status
### Core
Packages | NuGet
---------|------
AopCaching.Core|[](https://www.nuget.org/packages/AopCaching.Core)### Provider
Packages | NuGet
---------|------
AopCaching.InMemory|[](https://www.nuget.org/packages/AopCaching.InMemory)
AopCaching.Redis|[](https://www.nuget.org/packages/AopCaching.Redis)### Injection
Packages | NuGet
---------|------
AopCaching.InMemory.Autofac|[](https://www.nuget.org/packages/AopCaching.InMemory.Autofac)
AopCaching.InMemory.DependencyInjection|[](https://www.nuget.org/packages/AopCaching.InMemory.DependencyInjection)
AopCaching.Redis.Autofac|[](https://www.nuget.org/packages/AopCaching.Redis.Autofac)
AopCaching.Redis.DependencyInjection|[](https://www.nuget.org/packages/AopCaching.Redis.DependencyInjection)# Dependencies
Packages | Description
---------|------
[AspectCore](https://github.com/dotnetcore/AspectCore-Framework) | An Aspect-Oriented Programming based cross platform framework for .NET Core and .NET Framework.Core support for aspect-interceptor,dependency injection integration , web applications , data validation , and more.
[CSRedisCore](https://github.com/2881099/csredis) | A High-performance redis client.
[BloomFilter.NetCore](https://github.com/vla/BloomFilter.NetCore) | Library Bloom filters in C# with optional Redis-backing.# Usage
### Use Autofac
```csharp
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddControllersAsServices();
var builder = new ContainerBuilder();
builder.Populate(services);builder.AddAopCacheInRedis(options =>
{
options.Endpoints = new[] { "localhost:6379,password=123456,defaultDatabase=1", "localhost:6380,password=123456,defaultDatabase=1" };
options.Expiration = TimeSpan.FromMinutes(10);
options.UsePartition = true;
options.CacheMethodFilter = new CacheMethodFilter
{
IncludeService = new[] { "WebApplication.*Service" }
};
options.PreventPenetrationPolicy = new PreventPenetrationPolicy
{
BasicPolicy = new BasicPolicy
{
NoneResultKeyExpiration = TimeSpan.FromMinutes(10)
},
BloomFilterPolicy = new BloomFilterPolicy
{
Enable = true,
}
};
});builder.RegisterType().PropertiesAutowired().SingleInstance();
builder.RegisterAssemblyTypes(Assembly.GetEntryAssembly())
.Where(t => t.Name.EndsWith("Controller"))
.PropertiesAutowired().InstancePerLifetimeScope();
ApplicationContainer = builder.Build();
return new AutofacServiceProvider(ApplicationContainer);
}
```### Use DependencyInjection
```csharp
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1).AddControllersAsServices();
services.AddAopCacheInRedis(options =>
{
options.Endpoints = new[] { "localhost:6379,password=123456,defaultDatabase=1", "localhost:6380,password=123456,defaultDatabase=1" };
options.Expiration = TimeSpan.FromMinutes(10);
options.UsePartition = true;
options.CacheMethodFilter = new CacheMethodFilter
{
IncludeService = new[] { "WebApplication.*Service" }
};
options.PreventPenetrationPolicy = new PreventPenetrationPolicy
{
BasicPolicy = new BasicPolicy
{
NoneResultKeyExpiration = TimeSpan.FromMinutes(10)
},
BloomFilterPolicy = new BloomFilterPolicy
{
Enable = true,
}
};
});services.AddSingleton();
return services.BuildAspectInjectorProvider();
}
```### If you want to use a different configuration on some methods, you can use custom attribute.
```csharp
public class CacheService
{
[AopCaching(Key = "GetTime:{0}", BloomFilter = AopCacheFunctionSwitch.Enable, Expiration = 30)]
public virtual DateTime GetTime(int id)
{
return DateTime.Now;
}
}
```### Exclude methods
```csharp
public class CacheService
{
[NonAopCaching]
public virtual DateTime GetTime(int id)
{
return DateTime.Now;
}
}
```