A cache model, support static proxy class to cache result


Keywords
cache, memory, proxy, redis, roslyn, static
License
MIT
Install
Install-Package Ao.Cache.Serizlier.TextJson -Version 1.5.0-preview-3

Documentation

Ao.Cache

.NET Build codecov

A fast, easy, scalable cache, raw performace, cache proxy and lock middleware!

What is this

It is a fast, easy, scalable cache middleware, like that

request --> find cache ---miss---> find physical --> set in cache
                |
                L----> return

OR

request --> find cache ---miss---> find physical --> set in cache
                |
                L----> renewal cache time --> return

The library support auto do that, in Ao.Cache.Core

Proxy

Detail can see in Ao.Cache.Sample.CodeGen, it can be use in .NET7 AOT mode

The lib will auto-generate code in compile time, when use Ao.Cache.CodeGen(Support interface and class)

Like that(It support async or sync method, also support ValueType)

//Will generate proxy for class Student default for 
[CacheProxy(ProxyType =typeof(Student)),Head="a.b.c"]//Head is cache key prefx
public interface IStudent
{
    void Run();//Will not proxy, return is void

    int? Get<T>(int? a);//Support for generic methods

    int Get1(A a);//Will be warinning

    [CacheProxyMethod(CacheTime = "00:00:11")]
    Task<int?> Get2(A a);//Can async proxy

    ValueTask<int?> Get3(A a);//Can valuetask async proxy
}

Run in hand code

It support call expression to action cache.(The method actual no executed)

var creator = provider.GetRequiredService<ICacheHelperCreator>();
_ = finder.Get2(ax).Result;
Console.WriteLine(creator.DeleteAsync(() => finder.Get2(ax)).Result);//Delete by method expression but no executed.

Nuget

Package Id version
Ao.Cache.Core
Ao.Cache.Redis
Ao.Cache.InRedis
Ao.Cache.Serizlier.MessagePack
Ao.Cache.Serizlier.SpanJson
Ao.Cache.Serizlier.TextJson
Ao.Cache.CodeGen

Next

  • Add tests
  • Can AOT compile by no proxy
  • Completely non-invasive code
  • Improve performance

Benchmarks

The v1.5.0

benchmark