Skip to content

Commit

Permalink
#6939 Added a setting to disable query cache
Browse files Browse the repository at this point in the history
  • Loading branch information
skoshelev committed Dec 15, 2023
1 parent 1626480 commit df5862f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Libraries/Nop.Core/Configuration/CacheConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public partial class CacheConfig : IConfig
/// Gets or sets the default cache time in minutes
/// </summary>
public int DefaultCacheTime { get; protected set; } = 60;

/// <summary>
/// Gets or sets whether to disable linq2db query cache
/// </summary>
public bool LinqDisableQueryCache { get; protected set; } = false;
}
}
4 changes: 4 additions & 0 deletions src/Libraries/Nop.Data/NopDbStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Nop.Core.Configuration;
using Nop.Core.Infrastructure;
using Nop.Data.Mapping;
using Nop.Data.Migrations;
Expand Down Expand Up @@ -70,6 +71,9 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config
/// <param name="application">Builder for configuring an application's request pipeline</param>
public void Configure(IApplicationBuilder application)
{
var config = Singleton<AppSettings>.Instance.Get<CacheConfig>();

LinqToDB.Common.Configuration.Linq.DisableQueryCache = config.LinqDisableQueryCache;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public override void Up()
["Admin.Configuration.AppSettings.Data.WithNoLock"] = "Use NOLOCK",
["Admin.Configuration.AppSettings.Data.WithNoLock.Hint"] = "Check to add the NOLOCK hint to SELECT statements.",

//#6939
["Admin.Configuration.AppSettings.Cache.LinqDisableQueryCache"] = "Disable query cache",
["Admin.Configuration.AppSettings.Cache.LinqDisableQueryCache.Hint"] = "Disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects. For example, cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code. Or cache access synchronization could lead to bigger latencies than it saves.",
}, languageId);

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4464,6 +4464,12 @@
<LocaleResource Name="Admin.Configuration.AppSettings.Cache.DefaultCacheTime.Hint">
<Value>Set default cache time (in minutes).</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.AppSettings.Cache.LinqDisableQueryCache">
<Value>Disable query cache</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.AppSettings.Cache.LinqDisableQueryCache.Hint">
<Value>Disable LINQ expressions caching for queries. This cache reduces time, required for query parsing but have several side-effects. For example, cached LINQ expressions could contain references to external objects as parameters, which could lead to memory leaks if those objects are not used anymore by other code. Or cache access synchronization could lead to bigger latencies than it saves.</Value>
</LocaleResource>
<LocaleResource Name="Admin.Configuration.AppSettings.Cache.ShortTermCacheTime">
<Value>Short term cache time</Value>
</LocaleResource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public partial record CacheConfigModel : BaseNopModel, IConfigModel
[NopResourceDisplayName("Admin.Configuration.AppSettings.Cache.DefaultCacheTime")]
public int DefaultCacheTime { get; set; }

[NopResourceDisplayName("Admin.Configuration.AppSettings.Cache.LinqDisableQueryCache")]
public bool LinqDisableQueryCache { get; set; }

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@
<span asp-validation-for="CacheConfigModel.DefaultCacheTime"></span>
</div>
</div>
<div class="form-group row">
<div class="col-md-3">
<nop-label asp-for="CacheConfigModel.LinqDisableQueryCache" />
</div>
<div class="col-md-9">
<nop-editor asp-for="CacheConfigModel.LinqDisableQueryCache" />
<span asp-validation-for="CacheConfigModel.LinqDisableQueryCache"></span>
</div>
</div>
</div>

0 comments on commit df5862f

Please sign in to comment.