Files
Umbraco-CMS/src/Umbraco.Web/PublishedCache/NuCache/NuCacheComposer.cs

58 lines
2.5 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Configuration;
using System.Linq;
2020-07-03 13:30:40 +10:00
using Umbraco.Core;
2019-01-03 21:00:28 +01:00
using Umbraco.Core.Composing;
using Umbraco.Web.PublishedCache.NuCache.DataSource;
namespace Umbraco.Web.PublishedCache.NuCache
{
public class NuCacheComposer : ComponentComposer<NuCacheComponent>, ICoreComposer
2019-01-03 21:00:28 +01:00
{
public override void Compose(Composition composition)
2019-01-03 21:00:28 +01:00
{
base.Compose(composition);
2020-07-03 13:30:40 +10:00
var serializer = ConfigurationManager.AppSettings["Umbraco.Web.PublishedCache.NuCache.Serializer"];
composition.Register<INuCachePropertyOptionsFactory, AppSettingsNuCachePropertyMapFactory>();
composition.Register<Lz4DictionaryOfPropertyDataSerializer, Lz4DictionaryOfPropertyDataSerializer>();
2020-07-03 13:30:40 +10:00
if (serializer == "MsgPack")
{
var propertyDictionarySerializer = ConfigurationManager.AppSettings["Umbraco.Web.PublishedCache.NuCache.DictionaryOfPropertiesSerializer"];
if (propertyDictionarySerializer == "LZ4Map")
{
composition.Register(factory =>
{
var lz4Serializer = factory.GetInstance<Lz4DictionaryOfPropertyDataSerializer>();
return new ContentDataSerializer(lz4Serializer);
});
}
else
{
composition.Register(factory => new ContentDataSerializer(new DictionaryOfPropertyDataSerializer()));
}
composition.Register<IContentNestedDataSerializer, MsgPackContentNestedDataSerializer>();
2020-07-03 13:30:40 +10:00
}
else
{
composition.Register<IContentNestedDataSerializer, JsonContentNestedDataSerializer>();
composition.Register(factory => new ContentDataSerializer(new DictionaryOfPropertyDataSerializer()));
2020-07-03 13:30:40 +10:00
}
2019-01-03 21:00:28 +01:00
// register the NuCache database data source
composition.Register<IDataSource, DatabaseDataSource>();
// register the NuCache published snapshot service
// must register default options, required in the service ctor
composition.Register(factory => new PublishedSnapshotServiceOptions());
2019-01-03 21:00:28 +01:00
composition.SetPublishedSnapshotService<PublishedSnapshotService>();
// add the NuCache health check (hidden from type finder)
// TODO: no NuCache health check yet
2019-01-03 21:00:28 +01:00
//composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
}
2019-01-03 21:00:28 +01:00
}
}