Class CacheFactory
Helper class to instantiate new ICacheManager<TCacheValue> instances from configuration.
Inherited Members
Namespace:CacheManager.Core
Assembly:CacheManager.Core.dll
Syntax
public static class CacheFactory
Methods
| Improve this Doc View SourceBuild(Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the inline configuration defined by settings.
This Build method returns a ICacheManager<TCacheValue> with cache item type being Object.
Declaration
public static ICacheManager<object> Build(Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
ICacheManager<Object> | The cache manager instance. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build(settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
See Also
Build(String, Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the inline configuration defined by settings.
This Build method returns a ICacheManager
with cache item type being System.Object
.
The following example shows how to use this overload to build a CacheManagerConfiguration and pass it to the CacheFactory to create a new CacheManager instance.
var cache = cachefactory.build("mycachename", settings =>
{
settings
.withupdatemode(cacheupdatemode.up)
.withdictionaryhandle()
.enableperformancecounters()
.withexpiration(expirationmode.sliding, timespan.fromseconds(10));
});
cache.add("key", "value");
Declaration
public static ICacheManager<object> Build(string cacheName, Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
String | cacheName | The name of the cache manager instance. |
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
ICacheManager<Object> | The cache manager instance with cache item type being |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build("myCacheName", settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheName or settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
See Also
Build(Type, Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the given type and the inline configuration defined by settings. Use this overload if you cannot invoke the generic method, for example in conjunction with dependency injection.
Declaration
public static object Build(Type cacheValueType, Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build(typeof(string), settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
Build(Type, String, Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the given type and the inline configuration defined by settings. Use this overload if you cannot invoke the generic method, for example in conjunction with dependency injection.
Declaration
public static object Build(Type cacheValueType, string cacheName, Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
String | cacheName | The name of the cache manager instance. |
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build(typeof(string), "myCacheName", settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheName or settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
Build<TCacheValue>(Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the inline configuration defined by settings.
Declaration
public static ICacheManager<TCacheValue> Build<TCacheValue>(Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance with cache item type being |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build(settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
See Also
Build<TCacheValue>(String, Action<ConfigurationBuilderCachePart>)
Instantiates a cache manager using the inline configuration defined by settings.
Declaration
public static ICacheManager<TCacheValue> Build<TCacheValue>(string cacheName, Action<ConfigurationBuilderCachePart> settings)
Parameters
Type | Name | Description |
---|---|---|
String | cacheName | The name of the cache manager instance. |
Action<ConfigurationBuilderCachePart> | settings | The configuration. Use the settings element to configure the cache manager instance, add cache handles and also to configure the cache handles in a fluent way. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance with cache item type being |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var cache = CacheFactory.Build("myCacheName", settings =>
{
settings
.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryHandle()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheName or settings is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
See Also
FromConfiguration(Type, ICacheManagerConfiguration)
Instantiates a cache manager using the given cacheValueType and configuration.
Use this overload only if you cannot use the generic overload. The return type will be Object
.
This method can be used for example in conjunction with dependency injection frameworks.
Declaration
public static object FromConfiguration(Type cacheValueType, ICacheManagerConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
ICacheManagerConfiguration | configuration | The configured which will be used to configure the cache manager instance. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheValueType or configuration are null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
FromConfiguration(Type, String)
Instantiates a cache manager from app.config or web.config.
Use this overload only if you cannot use the generic overload. The return type will be Object
.
This method can be used for example in conjunction with dependency injection frameworks.
The cacheName must match with one cache element defined in your config file.
Declaration
public static object FromConfiguration(Type cacheValueType, string cacheName)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
String | cacheName | The name of the cache, must also match with the configured cache name. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheValueType or cacheName is null or an empty. |
InvalidOperationException | Thrown if there are configuration errors within the cacheManager section. Thrown if no cacheManager section is defined or on certain configuration errors related to the cache handles. |
FromConfiguration(Type, String, ICacheManagerConfiguration)
Instantiates a cache manager using the given cacheValueType and configuration.
Use this overload only if you cannot use the generic overload. The return type will be Object
.
This method can be used for example in conjunction with dependency injection frameworks.
Declaration
public static object FromConfiguration(Type cacheValueType, string cacheName, ICacheManagerConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
String | cacheName | The name of the cache. |
ICacheManagerConfiguration | configuration | The configured which will be used to configure the cache manager instance. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
FromConfiguration(Type, String, String)
Instantiates a cache manager from app.config or web.config.
Use this overload only if you cannot use the generic overload. The return type will be Object
.
This method can be used for example in conjunction with dependency injection frameworks.
The cacheName must match with one cache element defined in your config file.
Declaration
public static object FromConfiguration(Type cacheValueType, string cacheName, string sectionName)
Parameters
Type | Name | Description |
---|---|---|
Type | cacheValueType | The type of the cache item value. |
String | cacheName | The name of the cache. |
String | sectionName | The cache manager section name. |
Returns
Type | Description |
---|---|
Object | The cache manager instance. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheValueType, cacheName or sectionName is null or an empty. |
InvalidOperationException | Thrown if there are configuration errors within the cacheManager section. Thrown if no cacheManager section is defined or on certain configuration errors related to the cache handles. |
FromConfiguration<TCacheValue>(ICacheManagerConfiguration)
Instantiates a cache manager using the given configuration.
Declaration
public static ICacheManager<TCacheValue> FromConfiguration<TCacheValue>(ICacheManagerConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
ICacheManagerConfiguration | configuration | The configured which will be used to configure the cache manager instance. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance. |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Examples
The following example show how to build a CacheManagerConfiguration
and then
using the CacheFactory
to create a new cache manager instance.
var managerConfiguration = ConfigurationBuilder.BuildConfiguration<object>(settings =>
{
settings.WithUpdateMode(CacheUpdateMode.Up)
.WithDictionaryCacheHandle<object>>()
.EnablePerformanceCounters()
.WithExpiration(ExpirationMode.Sliding, TimeSpan.FromSeconds(10));
});
var cache = CacheFactory.FromConfiguration<object>(managerConfiguration);
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the configuration is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
FromConfiguration<TCacheValue>(String)
Instantiates a cache manager from app.config or web.config.
The cacheName must match with one cache element defined in your config file.
Declaration
public static ICacheManager<TCacheValue> FromConfiguration<TCacheValue>(string cacheName)
Parameters
Type | Name | Description |
---|---|---|
String | cacheName | The name of the cache, must also match with the configured cache name. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance. |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Examples
The following example show how to use the CacheFactory to create a new cache manager instance from app/web.config.
var cache = CacheFactory.FromConfiguration<object>("myCache");
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheName is null or an empty. |
InvalidOperationException | Thrown if there are configuration errors within the cacheManager section. Thrown if no cacheManager section is defined or on certain configuration errors related to the cache handles. |
See Also
FromConfiguration<TCacheValue>(String, ICacheManagerConfiguration)
Instantiates a cache manager using the given configuration.
Declaration
public static ICacheManager<TCacheValue> FromConfiguration<TCacheValue>(string cacheName, ICacheManagerConfiguration configuration)
Parameters
Type | Name | Description |
---|---|---|
String | cacheName | The name of the cache. |
ICacheManagerConfiguration | configuration | The configured which will be used to configure the cache manager instance. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance. |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the configuration is null. |
InvalidOperationException | Thrown on certain configuration errors related to the cache handles. |
FromConfiguration<TCacheValue>(String, String)
Instantiates a cache manager from app.config or web.config.
The cacheName must match with one cache element defined in your config file.
Declaration
public static ICacheManager<TCacheValue> FromConfiguration<TCacheValue>(string cacheName, string sectionName)
Parameters
Type | Name | Description |
---|---|---|
String | cacheName | The name of the cache. |
String | sectionName | The cache manager section name. |
Returns
Type | Description |
---|---|
ICacheManager<TCacheValue> | The cache manager instance. |
Type Parameters
Name | Description |
---|---|
TCacheValue | The type of the cache item value. |
Examples
The following example show how to use the CacheFactory to create a new cache manager instance from app/web.config.
var cache = CacheFactory.FromConfiguration<object>("cache", "section");
cache.Add("key", "value");
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if the cacheName or sectionName is null or an empty. |
InvalidOperationException | Thrown if there are configuration errors within the cacheManager section. Thrown if no cacheManager section is defined or on certain configuration errors related to the cache handles. |