NotableDateCachingExtensions Class
Definition
- Namespace
- Bodu.Globalization.Calendar
- Assembly
- Bodu.Globalization.Calendar.Caching.dll
- Package
- Bodu.Globalization.Calendar.Caching 1.0.0
Provides IServiceCollection extension methods that wrap a registered INotableDateService with a caching decorator.
public static class NotableDateCachingExtensions
- Inheritance
-
NotableDateCachingExtensions
- Inherited Members
Examples
builder.Services.AddNotableDateService(AmericasCalendarData.LoadResource("US"));
builder.Services.AddCachedNotableDateService(configure: o => o.Ttl = TimeSpan.FromDays(7));
Remarks
The registration decorates the existing INotableDateService in place: the previously registered
service becomes the inner service a CachingNotableDateService computes misses through, so consumers
continue to inject INotableDateService and transparently gain caching. An
INotableDateResourceProvider registered by AddReloadableNotableDateService is observed
automatically, so a reload invalidates the cache.
Methods
AddCachedNotableDateService(IServiceCollection, IConfiguration?, string, Action<NotableDateCachingOptions>?, Func<IServiceProvider, INotableDateCache>?)
Wraps the registered INotableDateService with a caching decorator, binding the caching options from configuration.
public static IServiceCollection AddCachedNotableDateService(this IServiceCollection services, IConfiguration? configuration, string sectionName = "Calendar:NotableDateCache", Action<NotableDateCachingOptions>? configure = null, Func<IServiceProvider, INotableDateCache>? cacheFactory = null)
Parameters
servicesIServiceCollectionThe service collection to modify.
configurationIConfigurationAn optional configuration root or section bound into the caching options.
sectionNamestringThe configuration section name. Defaults to
Calendar:NotableDateCache.configureAction<NotableDateCachingOptions>An optional callback applied after configuration binding.
cacheFactoryFunc<IServiceProvider, INotableDateCache>An optional factory producing the INotableDateCache. When null, a default per-territory TOML file cache is used.
Returns
- IServiceCollection
The same service collection, to allow chaining.
Exceptions
- ArgumentNullException
Thrown when
servicesis null.- ArgumentException
Thrown when
sectionNameis empty or white space.- InvalidOperationException
Thrown when no INotableDateService has been registered.
AddCachedNotableDateService(IServiceCollection, Action<NotableDateCachingOptions>?, Func<IServiceProvider, INotableDateCache>?)
Wraps the registered INotableDateService with a caching decorator, using the supplied cache or a default per-territory TOML file cache.
public static IServiceCollection AddCachedNotableDateService(this IServiceCollection services, Action<NotableDateCachingOptions>? configure = null, Func<IServiceProvider, INotableDateCache>? cacheFactory = null)
Parameters
servicesIServiceCollectionThe service collection to modify.
configureAction<NotableDateCachingOptions>An optional callback applied to the caching options.
cacheFactoryFunc<IServiceProvider, INotableDateCache>An optional factory producing the INotableDateCache from the service provider. When null, a default TomlNotableDateCache under the options'
CacheDirectoryis used. Supply a factory to choose the storage structure - for example an in-memory, JSON, SQLite, or distributed cache.
Returns
- IServiceCollection
The same service collection, to allow chaining.
Exceptions
- ArgumentNullException
Thrown when
servicesis null.- InvalidOperationException
Thrown when no INotableDateService has been registered.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |