Skip to content

About custom caching implementation. #149

Answered by Muratsavkli
Muratsavkli asked this question in Q&A
Discussion options

You must be logged in to vote

Ohh thank you again. I missed this point. Refactored the registering of AddChatGpt service with the same lifetime of the dbContext. By doing this I got rid of code duplication. As it seems below 👍
Program.cs :

builder.Services.AddChatGpt(builder.Configuration).WithCache<DatabaseMessageCache>(ServiceLifetime.Scoped);

DatabaseMessageCache.cs :

public class DatabaseMessageCache : IChatGptCache
{
	private readonly ApplicationDbContext _context;

	public DatabaseMessageCache(ApplicationDbContext context)
	{
		_context = context;
	}

	public async Task SetAsync(Guid conversationId, IEnumerable<ChatGptMessage> messages, TimeSpan expiration, CancellationToken cancellationToken = default)
	{
		var e…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@Muratsavkli
Comment options

@marcominerva
Comment options

@Muratsavkli
Comment options

Answer selected by marcominerva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants