dotnetcore / dotnetcore/EasyCaching

My Application crashed after I upgraded EasyCashing from version 0.5.6 to version 1.9.2 ( when caching Proxied Entity (EntityFrameworkCore 8.x))

Open
#572 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.1k
Forks
336
PR merge metrics
No merged PRs in 30d

Description

[TestEasyCache.zip](https://github.com/user-attachments/files/21155663/TestEasyCache.zip)

EasyCaching.InMemory 1.9.2
EntityFrameworkCore 8.0.18

This issue does not happen for version 0.5.6 and version 0.6.1

Startup.cs
`namespace EasyCaching.Demo.ResponseCaching
{
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();

services.AddEasyCaching(x => { x.UseInMemory("default"); });
//services.AddSqlite("Data Source=my_data.db");
services.AddDbContextPool(optionsBuilder =>
{
// this configuration seems does not work with eazy cache?
optionsBuilder.UseLazyLoadingProxies();

optionsBuilder.UseSqlite("Data Source=my_data.db");
});

}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//app.UseEasyCachingResponseCaching();
app.UseStaticFiles();

app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}`

HomeController.cs
`namespace EasyCaching.Demo.ResponseCaching.Controllers
{
using EasyCaching.Core;
using EasyCaching.Demo.ResponseCaching.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.Threading.Tasks;

public class HomeController : Controller
{
private readonly IEasyCachingProvider _provider;
private readonly MyDbContext _myDbContext;
public HomeController(IEasyCachingProviderFactory easyCachingProviderFactory, MyDbContext myDbContext)
{
_provider = easyCachingProviderFactory.GetCachingProvider("default");
_myDbContext = myDbContext;
}
[ResponseCache(Duration = 20)]
public async Task Index()
{

_myDbContext.Database.Migrate();
var test = await _provider.GetAsync("k1", async () =>
{
for (var i = 0; i < 100; i++)
{
var product = await _provider.GetAsync("product1", async () =>
{
var p = await _myDbContext.Products.FirstOrDefaultAsync();
// the real type of p is Castle.Proxies.ProductProxy
return p;// new Product() { Name = p.Name};
}, TimeSpan.FromSeconds(60));
}
return new object();
}, TimeSpan.FromSeconds(60));

return Ok(test);
}
}
}`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.