Skip to content

Commit

Permalink
Add module initializer to opportunistically fold cctor checks
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-sunset committed Jun 6, 2022
1 parent f7260ce commit f3f08f7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/FastCache.Cached/CacheStaticHolder.cs
@@ -1,7 +1,33 @@
using FastCache.Collections;
using FastCache.Extensions;
using FastCache.Helpers;
using FastCache.Services;
using NonBlocking;

namespace FastCache;

#if NET5_0_OR_GREATER
#pragma warning disable CA2255 // Static initialization to ensure cctor checks are removed in JITted code
internal static class CacheStaticHolder
{
[ModuleInitializer]
public static void Initialize()
{
RuntimeHelpers.RunClassConstructor(typeof(Constants).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(CacheStaticHolder<,>).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(CacheManager).TypeHandle);

RuntimeHelpers.RunClassConstructor(typeof(Cached<,>).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(Cached).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(CachedExtensions).TypeHandle);
RuntimeHelpers.RunClassConstructor(typeof(CachedRange).TypeHandle);

RuntimeHelpers.RunClassConstructor(typeof(TimeUtils).TypeHandle);
}
}
#pragma warning restore CA2255
#endif

internal static class CacheStaticHolder<K, V> where K : notnull
{
internal static readonly ConcurrentDictionary<K, CachedInner<V>> Store = new(concurrencyLevel: 1, capacity: 1048576);
Expand Down

0 comments on commit f3f08f7

Please sign in to comment.