I'm not sure about the legitimate translation, but below is a piece of code used in a Blazor that in the case of a user refresh a page while the cache is empty.
signalr restarts the procedure faster than the cache is validated.
public class GetPaginatedNorpaAgendaHandler(IServiceProvider serviceProvider,
IOptions<NorpaSettings> settings, ICacheService cacheService)
: IRequestHandler<GetPaginatedNorpaAgendaCommand, PaginatedList<Models.NorpaAgenda_rec>>
{
public async Task<PaginatedList<Models.NorpaAgenda_rec>> Handle(GetPaginatedNorpaAgendaCommand request, CancellationToken cancellationToken)
{
if (request.Cached)
{
var cacheKey = GenerateCacheKey(request);
return (await cacheService.GetSetCachedItemAsync(cacheKey, async () => await FetchAgendaAsync(request, cancellationToken)))!;
}
return await FetchAgendaAsync(request, cancellationToken);
}
private string GenerateCacheKey(GetPaginatedNorpaAgendaCommand request)
{
var queryString = request.Cached.ToString()+request.PageIndex.ToString()+request.AmountPerPage.ToString();
var hash = SHA256.HashData(Encoding.UTF8.GetBytes(queryString));
return typeof(Models.NorpaAgenda_rec).ToCacheKey(Convert.ToBase64String(hash));
}
private async Task<PaginatedList<Models.NorpaAgenda_rec>> FetchAgendaAsync(GetPaginatedNorpaAgendaCommand request, CancellationToken cancellationToken)
{
NorpaAgenda fAgenda = new();
var fconnection = await GetConnect();
using (FbTransaction ftransaction = await fconnection.BeginTransactionAsync(cancellationToken))
{
var clauseWhere = " 1 = 1 rows " + ((request.PageIndex - 1) * request.AmountPerPage).ToString() + " to " + request.AmountPerPage.ToString();
var ftmp = await fAgenda.SelectFromWheretoListRecord(ftransaction, clauseWhere);
await ftransaction.CommitAsync();
await ftransaction.DisposeAsync();
return ftmp.ToPaginatedList(request.PageIndex, request.AmountPerPage);
}
}
private async Task<FbConnection> GetConnect()
{
return (await cacheService.GetSetCachedItemAsync("GetPaginatedNorpaAgendaCommandFbConn", async () =>
{
FbConnection fconnection = new(settings.Value.ConnectionString!);
await fconnection.OpenAsync();
return fconnection!;
}, 600))!;
}
}
-----Message d'origine-----
De :
firebird-n...@googlegroups.com <
firebird-n...@googlegroups.com> De la part de Jirí Cincura
Envoyé : mardi 15 avril 2025 11:51
À : 'Mr. John' via firebird-net-provider <
firebird-n...@googlegroups.com>
Objet : Re: [firebird-net-provider] Re: A transaction is currently active. Parallel transactions are not supported
--
Support the ongoing development of Firebird! Consider donating to the Firebird Foundation and help ensure its future. Every contribution makes a difference. Learn more and donate here:
https://www.firebirdsql.org/donate.
---
You received this message because you are subscribed to the Google Groups "firebird-net-provider" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
firebird-net-pro...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/firebird-net-provider/e0e87042-9d8e-497e-a0d2-e6340a00565f%40app.fastmail.com.