Skip to content

Commit 230d424

Browse files
committed
- Added support for automatic detection and use of universal fallback configuration file named 'LazyCacheHelpers.config' to allow for easier configuration TTL values without necessitating (but of course you still can) that configs exist in the main App.config, Web.config file and/or manage different config files for multi-targeting Unit Test projects, etc.
- Add compilation target for net6.0+ to minimize dependency footprints (remove unnecessary dependencies brought in by netstandard2.0. - Update dependencies to as high as possible to resolve issues with Vulnerabilities and Deprecated versions while maintaining support for net6.0 (for now). - Synced the version with the main package for easier management and to correctly sync with GitHub tags. - Fixed Unit Test project compilation and all tests are running successfully.
1 parent 227ec46 commit 230d424

File tree

6 files changed

+101
-71
lines changed

6 files changed

+101
-71
lines changed

LazyCacheHelpers.ConfigurationManager/LazyCacheConfigurationManager.cs

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Configuration;
33
using System.Diagnostics;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Runtime.CompilerServices;
47

58
namespace LazyCacheHelpers
69
{
@@ -12,17 +15,43 @@ namespace LazyCacheHelpers
1215
/// </summary>
1316
public class LazyCacheConfigurationManager
1417
{
18+
public static string LazyCacheHelpersFallbackConfigFileName { get; } = "LazyCacheHelpers.config";
19+
20+
private static Configuration LazyCacheHelpersConfig { get; set; }
21+
1522
public static void BootstrapConfigurationManager()
1623
{
24+
var lazyCacheHelpersFallbackConfigFilePath = Path.Combine(AppContext.BaseDirectory, LazyCacheHelpersFallbackConfigFileName);
25+
if (LazyCacheHelpersConfig is null && File.Exists(lazyCacheHelpersFallbackConfigFilePath))
26+
{
27+
LazyCacheHelpersConfig = ConfigurationManager.OpenMappedExeConfiguration(
28+
new ExeConfigurationFileMap() { ExeConfigFilename = lazyCacheHelpersFallbackConfigFilePath },
29+
ConfigurationUserLevel.None
30+
);
31+
}
32+
1733
LazyCacheConfig.BootstrapConfigValueReader(configKeyName =>
1834
{
1935
#if DEBUG
20-
var configFilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
21-
Debug.WriteLine($"Looking for Configuration File: [{configFilePath}]");
36+
var defaultConfigFilePath = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
37+
Debug.WriteLine($"Looking for Configuration value [{configKeyName}] in Default configuration file [{defaultConfigFilePath}]...");
38+
#endif
39+
40+
string configValue = ConfigurationManager.AppSettings[configKeyName];
41+
if (string.IsNullOrWhiteSpace(configValue) && LazyCacheHelpersConfig != null)
42+
{
43+
#if DEBUG
44+
Debug.WriteLine($"Configuration value [{configKeyName}] was not found in the Default configuration file...");
45+
Debug.WriteLine($"Now looking for Configuration value in fallback configuration file: [{LazyCacheHelpersFallbackConfigFileName}]...");
46+
#endif
47+
48+
configValue = LazyCacheHelpersConfig.AppSettings?.Settings[configKeyName]?.Value;
49+
}
50+
51+
#if DEBUG
52+
Debug.WriteLine($"Configuration value [{configKeyName}] == [{ configValue ?? "null" }]");
2253
#endif
2354

24-
var appSettings = ConfigurationManager.AppSettings;
25-
String configValue = appSettings[configKeyName];
2655
return configValue;
2756
});
2857
}
Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
4+
<Version>1.3.3</Version>
5+
<Description>Extension package for the LazyCacheHelpers Library to provide easy to use helpers to read cache configuration values from App.Config or Web.config files using System.Configuration; making things like enabling/disabling and dynamic fallback from specialized to generalized config values much easier to implement.</Description>
6+
<Copyright>Copyright (c) 2018</Copyright>
7+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
8+
<Authors>BBernard / CajunCoding</Authors>
9+
<Company>CajunCoding</Company>
10+
<PackageProjectUrl>https://github.com/cajuncoding/LazyCacheHelpers</PackageProjectUrl>
11+
<RepositoryUrl>https://github.com/cajuncoding/LazyCacheHelpers</RepositoryUrl>
12+
<PackageTags>cache caching memory memorycache in-memory lazy loading load self populate populating abstraction abstract thread threadsafe thread-safe safe performance optimization optimize server utilization</PackageTags>
13+
<PackageReleaseNotes>
14+
- Added support for automatic detectiona and use of universal fallback configuration file named 'LazyCacheHelpers.config' to allow for easier configuration TTL values without necessitating (but of course you still can) that configs exist in the main App.config, Web.config file and/or manage different config files for multi-targeting Unit Test projects, etc.
15+
- Add compilation target for net6.0+ to minimize dependency footprints (remove unnecessary dependencies brought in by netstandard2.0.
16+
- Update dependencies to as high as possible to resolve issues with Vulnerabilities and Deprecated versions while maintaining support for net6.0 (for now).
17+
- Synced the version with the main package for easier management and to correctly sync with GitHub tags.
218

3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<Description>Extension package for the LazyCacheHelpers Library to provide easy to use helpers to read cache configuration values from App.Config or Web.config files using System.Configuration; making things like enabling/disabling and dynamic fallback from specialized to generalized config values much easier to implement.</Description>
6-
<Copyright>Copyright (c) 2018</Copyright>
7-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
8-
<Authors>BBernard / CajunCoding</Authors>
9-
<Company>CajunCoding</Company>
10-
<PackageProjectUrl>https://github.com/cajuncoding/LazyCacheHelpers</PackageProjectUrl>
11-
<RepositoryUrl>https://github.com/cajuncoding/LazyCacheHelpers</RepositoryUrl>
12-
<PackageTags>cache caching memory memorycache in-memory lazy loading load self populate populating abstraction abstract thread threadsafe thread-safe safe performance optimization optimize server utilization</PackageTags>
13-
<PackageReleaseNotes>
14-
- Synced the version with the main package for easier management and to correctly sync with GitHub tags.
15-
- Restored LazyCacheConfig to the original library with support reading values dynamically from Configuration; no longer in this library.
16-
- Added support for Bootstrapping the new dynamic Configuration Reader Func (Delegate) with a default implementation that reads from ConfigurationManager.AppSettings.
19+
Prior Release Notes:
20+
- Restored LazyCacheConfig to the original library with support reading values dynamically from Configuration; no longer in this library.
21+
- Added support for Bootstrapping the new dynamic Configuration Reader Func (Delegate) with a default implementation that reads from ConfigurationManager.AppSettings.
22+
- Refactored as .Net Standard v2.0 compatible Library for greater compatibility
23+
- Now uses System.ConfigurationManagement package.
24+
- Breaking change if these helpers were used from prior version v1.0.1 of LazyCacheHelpers; the helpers now require renaming all calls from LazyCachePolicy static helper to now use LazyCachePolicyFromConfig static helper.
25+
- Initial nuget release for .Net Framework.
26+
</PackageReleaseNotes>
27+
</PropertyGroup>
1728

18-
Prior Release Notes:
19-
- Refactored as .Net Standard v2.0 compatible Library for greater compatibility
20-
- Now uses System.ConfigurationManagement package.
21-
- Breaking change if these helpers were used from prior version v1.0.1 of LazyCacheHelpers; the helpers now require renaming all calls from LazyCachePolicy static helper to now use LazyCachePolicyFromConfig static helper.
22-
- Initial nuget release for .Net Framework.
23-
</PackageReleaseNotes>
24-
<Version>1.0.4</Version>
25-
</PropertyGroup>
29+
<ItemGroup>
30+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.1" />
31+
</ItemGroup>
2632

27-
<ItemGroup>
28-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
29-
</ItemGroup>
30-
31-
<ItemGroup>
32-
<ProjectReference Include="..\LazyCacheHelpers\LazyCacheHelpers.csproj" />
33-
</ItemGroup>
33+
<ItemGroup>
34+
<ProjectReference Include="..\LazyCacheHelpers\LazyCacheHelpers.csproj" />
35+
</ItemGroup>
3436

3537
</Project>
Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,34 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFrameworks>net48;net6.0;net8.0</TargetFrameworks>
4+
<IsPackable>false</IsPackable>
5+
</PropertyGroup>
26

3-
<PropertyGroup>
4-
<TargetFramework>net6</TargetFramework>
7+
<ItemGroup>
8+
<Compile Remove="Properties\**" />
9+
<EmbeddedResource Remove="Properties\**" />
10+
<None Remove="Properties\**" />
11+
</ItemGroup>
512

6-
<IsPackable>false</IsPackable>
7-
</PropertyGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="3.9.3" />
16+
<PackageReference Include="MSTest.TestFramework" Version="3.9.3" />
17+
<PackageReference Include="coverlet.collector" Version="6.0.4">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
822

9-
<ItemGroup>
10-
<Compile Remove="Properties\**" />
11-
<EmbeddedResource Remove="Properties\**" />
12-
<None Remove="Properties\**" />
13-
</ItemGroup>
23+
<ItemGroup>
24+
<ProjectReference Include="..\LazyCacheHelpers.ConfigurationManager\LazyCacheHelpers.ConfigurationManager.csproj" />
25+
<ProjectReference Include="..\LazyCacheHelpers\LazyCacheHelpers.csproj" />
26+
</ItemGroup>
1427

15-
<ItemGroup>
16-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
17-
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
18-
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
19-
<PackageReference Include="coverlet.collector" Version="3.0.1">
20-
<PrivateAssets>all</PrivateAssets>
21-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
22-
</PackageReference>
23-
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
24-
</ItemGroup>
25-
26-
<ItemGroup>
27-
<ProjectReference Include="..\LazyCacheHelpers.ConfigurationManager\LazyCacheHelpers.ConfigurationManager.csproj" />
28-
<ProjectReference Include="..\LazyCacheHelpers\LazyCacheHelpers.csproj" />
29-
</ItemGroup>
30-
31-
<ItemGroup>
32-
<None Update="testhost.dll.config">
33-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
34-
</None>
35-
</ItemGroup>
28+
<ItemGroup>
29+
<None Update="LazyCacheHelpers.config">
30+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
31+
</None>
32+
</ItemGroup>
3633

3734
</Project>
File renamed without changes.

LazyCacheHelpers.Tests/TestAssemblyStartup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
namespace LazyCacheHelpers.Tests
55
{
66
[TestClass]
7-
internal class TestAssemblyStartup
7+
public class TestAssemblyStartup
88
{
99
[AssemblyInitialize]
10-
public static void AssemblyInit(TestContext context)
10+
public static void AssemblyInit(TestContext testContext)
1111
{
1212
LazyCacheConfigurationManager.BootstrapConfigurationManager();
1313
}

LazyCacheHelpers/LazyCacheHelpers.csproj

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2.0;net6.0</TargetFrameworks>
4+
<Version>1.3.3</Version>
55
<Copyright>Copyright (c) 2018</Copyright>
66
<PackageLicenseExpression>MIT</PackageLicenseExpression>
77
<Authors>BBernard / CajunCoding</Authors>
@@ -11,9 +11,12 @@
1111
<Description>Library for leveraging the power of the Lazy class to enable high performance caching at all layers of an application. It provides support for both Sync and Async Lazy caching operations in an extremely lightweight and simple footprint -- with passive cache coding style using Lambdas to maximize server utilization and performance with a blocking, or self-populating, cache implementation!</Description>
1212
<PackageTags>cache caching memory memorycache in-memory lazy loading load self populate populating abstraction abstract thread threadsafe thread-safe safe performance optimization optimize server utilization</PackageTags>
1313
<PackageReleaseNotes>
14-
- Add support to specify custom key comparer (e.g. StringComparer.OrdinalIgnoreCase) in LazyStaticInMemoryCache.
14+
- Add compilation target for net6.0+ to minimize dependency footprints (remove unnecessary dependencies brought in by netstandard2.0.
15+
- Update dependencies to as high as possible to resolve issues with Vulnerabilities and Deprecated versions while maintaining support for net6.0 (for now).
16+
1517

1618
Prior Release Notes:
19+
- Add support to specify custom key comparer (e.g. StringComparer.OrdinalIgnoreCase) in LazyStaticInMemoryCache.
1720
- Added support for inheriting from the new ILazySelfExpiringCacheResult&lt;TValue&gt;, with protected property setters, as well as small param naming improvements.
1821
- Add support for Self Expiring cache results that return the CachePolicy/Cache TTL/etc. along with the Cache Result; ideal when the cache TTL is not
1922
known ahead of time in use cases such as external API results that also return a lifespan for the data such as Auth API Tokens, etc.
@@ -31,7 +34,6 @@
3134
- Now fully supported as a .Net Standard 2.0 library (sans Configuration reader helpers) whereby you can specify the timespan directly for Cache Policy initialization.
3235
- Initial nuget release for .Net Framework.
3336
</PackageReleaseNotes>
34-
<Version>1.3.2</Version>
3537
</PropertyGroup>
3638

3739
<ItemGroup>
@@ -40,7 +42,7 @@
4042

4143
<ItemGroup>
4244
<PackageReference Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
43-
<PackageReference Include="System.Runtime.Caching" Version="5.0.0" />
45+
<PackageReference Include="System.Runtime.Caching" Version="8.0.1" />
4446
</ItemGroup>
4547

4648
<ItemGroup>

0 commit comments

Comments
 (0)