41 lines
1.1 KiB
C#
Raw Normal View History

2024-09-30 17:10:43 +08:00
using System;
2024-10-25 19:11:43 +08:00
using System.Threading.Tasks;
2024-09-30 17:10:43 +08:00
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
2024-10-08 14:41:41 +08:00
using JiShe.CollectBus.Protocol.Contracts.Models;
2024-09-30 17:10:43 +08:00
using Microsoft.Extensions.Caching.Distributed;
2024-10-12 23:42:15 +08:00
using TouchSocket.Sockets;
2024-09-30 17:10:43 +08:00
namespace JiShe.CollectBus.Protocol.Contracts.Abstracts
{
2024-10-25 19:11:43 +08:00
public abstract class BaseProtocolPlugin(IDistributedCache cache) : IProtocolPlugin
2024-09-30 17:10:43 +08:00
{
2024-10-25 19:11:43 +08:00
public abstract Task<ProtocolInfo> GetAsync();
2024-09-30 17:10:43 +08:00
2024-10-25 19:11:43 +08:00
public virtual Task ReceivedAsync(ITcpSessionClient client, ReceivedDataEventArgs e)
2024-09-30 17:10:43 +08:00
{
2024-10-25 19:11:43 +08:00
return Task.CompletedTask;
2024-09-30 17:10:43 +08:00
}
2024-10-25 19:11:43 +08:00
public virtual Task SendAsync()
{
return Task.CompletedTask;
}
2024-09-30 17:10:43 +08:00
2024-10-25 19:11:43 +08:00
public virtual async Task LoadAsync()
2024-09-30 17:10:43 +08:00
{
2024-10-25 19:11:43 +08:00
var result = cache.GetString("myKey");
2024-09-30 17:10:43 +08:00
if (result == null)
{
result = "Calculated Data";
2024-10-25 19:11:43 +08:00
cache.SetString("myKey", result, new DistributedCacheEntryOptions
2024-09-30 17:10:43 +08:00
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10)
});
}
2024-10-25 19:11:43 +08:00
await Task.CompletedTask;
2024-09-30 17:10:43 +08:00
}
}
}