Skip to content

Commit 227ec46

Browse files
committed
- Add support to specify custom key comparer (e.g. StringComparer.OrdinalIgnoreCase) in LazyStaticInMemoryCache.
- Nuget updates to publish v1.3.2
1 parent 316e784 commit 227ec46

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

LazyCacheHelpers/LazyCacheHelpers.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@
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-
- v1.3.1 Added support for inheriting from the new ILazySelfExpiringCacheResult&lt;TValue&gt;, with protected property setters, as well as small param naming improvements.
14+
- Add support to specify custom key comparer (e.g. StringComparer.OrdinalIgnoreCase) in LazyStaticInMemoryCache.
15+
16+
Prior Release Notes:
17+
- Added support for inheriting from the new ILazySelfExpiringCacheResult&lt;TValue&gt;, with protected property setters, as well as small param naming improvements.
1518
- 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
1619
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.
1720
- This should not be a breaking change as this support was now added via net new interfaces ILazyCacheHandlerSelfExpiring and ILazySelfExpiringCacheResult.
1821
- Added support to now easily inject/bootstrap the DefaultLazyCache static implementation with your own ILazyCacheRepository, eliminating the need to have your own
1922
Static implementaiton if you don't want to duplicate it; though encapsulating in your own static facade is usually a good idea.
2023
- Implemented IDisposable support for existing LazyCacheHandler and LazyCacheRepositories to support better cleanup of resources
21-
22-
Prior Release Notes:
2324
- Add support for Clearing the Lazy Static In-memory Cache (wrapper for Lazy caching pattern for sync or async results based on the underlying ConcurrentDictionary&lt;Lazy&lt;T&gt;&gt;).
2425
- Add support for Clearing the Cache and for getting the Cache Count; implemented for DefaultLazyCache as well as the Static In-memory caches.
2526
- Restored LazyCacheConfig class capabilities for reading values dynamically from Configuration.
@@ -30,7 +31,7 @@
3031
- 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.
3132
- Initial nuget release for .Net Framework.
3233
</PackageReleaseNotes>
33-
<Version>1.3.1</Version>
34+
<Version>1.3.2</Version>
3435
</PropertyGroup>
3536

3637
<ItemGroup>

LazyCacheHelpers/LazyStaticInMemoryCache.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Concurrent;
4+
using System.Collections.Generic;
35
using System.Threading.Tasks;
46

57
namespace LazyCacheHelpers
@@ -24,10 +26,21 @@ namespace LazyCacheHelpers
2426
/// </summary>
2527
public class LazyStaticInMemoryCache<TKey, TValue>
2628
{
27-
protected readonly ConcurrentDictionary<TKey, Lazy<TValue>> _lazySyncCache = new ConcurrentDictionary<TKey, Lazy<TValue>>();
28-
protected readonly ConcurrentDictionary<TKey, Lazy<Task<TValue>>> _lazyAsyncCache = new ConcurrentDictionary<TKey, Lazy<Task<TValue>>>();
29+
protected readonly ConcurrentDictionary<TKey, Lazy<TValue>> _lazySyncCache;
30+
protected readonly ConcurrentDictionary<TKey, Lazy<Task<TValue>>> _lazyAsyncCache;
2931
protected readonly object _padLock = new object();
3032

33+
public LazyStaticInMemoryCache(IEqualityComparer<TKey> keyComparer = null)
34+
{
35+
_lazySyncCache = keyComparer == null
36+
? new ConcurrentDictionary<TKey, Lazy<TValue>>()
37+
: new ConcurrentDictionary<TKey, Lazy<TValue>>(keyComparer);
38+
39+
_lazyAsyncCache = keyComparer == null
40+
? new ConcurrentDictionary<TKey, Lazy<Task<TValue>>>()
41+
: new ConcurrentDictionary<TKey, Lazy<Task<TValue>>>(keyComparer);
42+
}
43+
3144
/// Initialize a new Synchronous value factory for lazy loading a value from an expensive Async process, and execute the value factory at most one time (ever, across any/all threads).
3245
/// This provides a robust blocking cache mechanism backed by the Lazy<> class for high performance lazy loading of data that rarely ever changes.
3346
/// The resulting value will be immediately returned as fast as possible, and if another thread already initialized it and is working on it then you will benefit from the work

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ OR use the ConfigurationManager Bootstrap helper above if you still use (Depreca
6060
it'll wire up a default reader for you (see below)!
6161

6262
## Release Notes:
63-
### v1.3
63+
### v1.3.2
64+
- Add support to specify custom key comparer (e.g. StringComparer.OrdinalIgnoreCase) in LazyStaticInMemoryCache.
65+
66+
### v1.3.1
6467
- Add support for Self Expiring cache results where the value factory may now return the CachePolicy/Cache TTL/etc. along with the Cache Result.
6568
- This is ideal when the cache TTL is not known ahead of time in use cases such as external API results that also return a lifespan for the data
6669
such as Auth API Tokens, etc.

0 commit comments

Comments
 (0)