Skip to content

Instantly share code, notes, and snippets.

View casper-rasmussen's full-sized avatar

Casper Aagaard Rasmussen casper-rasmussen

View GitHub Profile
class EPiServerAwareKeyBuilder : IKeyBuilder
{
private readonly IKeyBuilder _keyBuilder = new KeyBuilder();
public string BuildKey(string controllerName)
{
return this._keyBuilder.BuildKey(controllerName);
}
public string BuildKey(string controllerName, string actionName)
public class ContentDonutOutputCacheAttribute : DonutOutputCacheAttribute
{
public ContentDonutOutputCacheAttribute()
: base(new KeyGenerator(new EPiServerAwareKeyBuilder()), new OutputCacheManager(OutputCache.Instance, new EPiServerAwareKeyBuilder()), (IDonutHoleFiller)new DonutHoleFiller((IActionSettingsSerialiser)new EncryptingActionSettingsSerialiser((IActionSettingsSerialiser)new ActionSettingsSerialiser(), (IEncryptor)new Encryptor())), (ICacheSettingsManager)new CacheSettingsManager(), (ICacheHeadersHelper)new CacheHeadersHelper())
{
}
}
public void StartListen()
{
//Bind our local publish events
DataFactory.Instance.PublishedContent += (sender, args) => this.PurgeOutputCacheByContent(args.Content);
//More code comes here in later snippet...
}
public void StartListen()
{
//Bind our local publish events
DataFactory.Instance.PublishedContent += (sender, args) => this.PurgeOutputCacheByContent(args.Content);
if (!this._eventRegistry.Enabled)
return;
//Finding the event for EPiServers RemoteCacheSynchronization-RemoveFromCache
//We are only listening to.
private static IEnumerable<string> RemoteEventPatterns = new List<string>()
{
"EPLanguageData:([0-9]+)$",
"EP:ContentVersion:([0-9]+)$",
@"EPContentVersion:([0-9_]+)$"
};
private void ChangeEventOnRaised(object sender, EventNotificationEventArgs eventNotificationEventArgs)
{
void PurgeOutputCacheByContent(IContent content)
{
IEnumerable<TemplateModel> templateModels = this._templateModelRepository.List(content.GetOriginalType());
RouteValueDictionary routeValues = new RouteValueDictionary();
routeValues.Add("currentcontent", content);
foreach (TemplateModel model in templateModels)
{
this._query = this._query.For(searchQuery)
.InField((content) => content.Title) //Include important field
.AndInField((content) => content.MainBody) //Include important field
.AddMatchingQueryStringFor(searchQuery, (content) => content.SupportingText) //Inclue non-important field and require that all words are within
this._query = this._query.For(searchQuery)
.InField((content) => content.Title) //Include important field
.AndInField((content) => content.MainBody) //Include important field
public static IQueriedSearch<T> AddMatchingQueryStringFor<T>(this ITypeSearch<T> search, string queryString, Expression<Func<T, string>> fieldSelector)
{
var fieldName = search.Client.Conventions.FieldNameConvention
.GetFieldNameForAnalyzed(fieldSelector);
//Split words by space
string[] words = queryString.Split(' ');
return new Search<T, WildcardQuery>(search, context =>
{
"bool":{
"must":[
{
"query_string":{
"fields":[
"PageTitle$$string.standard",
"MainBody$$string.standard"
],
"query":"Manage On-Premise License",
"default_operator":"AND"