Remove LastSoldCount, Add LastIncreSoldCount. https://github.com/Qtoss-AI/QtossTransformer/pull/11
This commit is contained in:
parent
e579dabb13
commit
7527f783d8
|
|
@ -10,19 +10,23 @@ public class SharpCacheAttribute : MoAttribute
|
|||
public static IServiceProvider Services { get; set; } = null!;
|
||||
|
||||
private int _minutes;
|
||||
private string _prefix;
|
||||
|
||||
public SharpCacheAttribute(int minutes, string prefix = "cache")
|
||||
public SharpCacheAttribute(int minutes = 60)
|
||||
{
|
||||
_minutes = minutes;
|
||||
_prefix = prefix;
|
||||
}
|
||||
|
||||
public override void OnEntry(MethodContext context)
|
||||
{
|
||||
var settings = Services.GetRequiredService<SharpCacheSettings>();
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var cache = Services.GetRequiredService<ICacheService>();
|
||||
|
||||
var key = GetCacheKey(context);
|
||||
var key = GetCacheKey(settings, context);
|
||||
var value = cache.GetAsync(key, context.TaskReturnType).Result;
|
||||
if (value != null)
|
||||
{
|
||||
|
|
@ -32,18 +36,24 @@ public class SharpCacheAttribute : MoAttribute
|
|||
|
||||
public override void OnSuccess(MethodContext context)
|
||||
{
|
||||
var settings = Services.GetRequiredService<SharpCacheSettings>();
|
||||
if (!settings.Enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var cache = Services.GetRequiredService<ICacheService>();
|
||||
|
||||
if (context.ReturnValue != null)
|
||||
{
|
||||
var key = GetCacheKey(context);
|
||||
var key = GetCacheKey(settings, context);
|
||||
cache.SetAsync(key, context.ReturnValue, new TimeSpan(0, _minutes, 0)).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
private string GetCacheKey(MethodContext context)
|
||||
private string GetCacheKey(SharpCacheSettings settings, MethodContext context)
|
||||
{
|
||||
var key = _prefix + "-" + context.Method.Name;
|
||||
var key = settings.Prefix + "-" + context.Method.Name;
|
||||
foreach (var arg in context.Arguments)
|
||||
{
|
||||
if (arg is null)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
namespace BotSharp.Abstraction.Infrastructures;
|
||||
|
||||
public class SharpCacheSettings
|
||||
{
|
||||
public bool Enabled { get; set; } = false;
|
||||
public string Prefix { get; set; } = "cache";
|
||||
}
|
||||
|
|
@ -16,9 +16,15 @@ public static class BotSharpCoreExtensions
|
|||
{
|
||||
services.AddScoped<ISettingService, SettingService>();
|
||||
services.AddScoped<IUserService, UserService>();
|
||||
services.AddSingleton<ICacheService, CacheService>();
|
||||
|
||||
services.AddSingleton<DistributedLocker>();
|
||||
|
||||
// Register cache service
|
||||
var cacheSettings = new SharpCacheSettings();
|
||||
config.Bind("SharpCache", cacheSettings);
|
||||
services.AddSingleton(x => cacheSettings);
|
||||
services.AddSingleton<ICacheService, CacheService>();
|
||||
|
||||
RegisterPlugins(services, config);
|
||||
ConfigureBotSharpOptions(services, configOptions);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue