Strange caching behaviour for custom property editor
Hi guys,
I have a custom property editor that is being used to specify the days and times certain activities take place on.
When I iterate over the schedules for the first time they have the correct values, but on subsequent requests every element has the same value - the last item according to 'Sort Order' in Umbraco.
It's as if the values are being cached somewhere / somehow using the same key, but I cannot for the life of me figure out what is going on.
I have tried the following to no avail:
Set different PropertyCacheLevel on the ValueConverter, tried None, Element, Elements, Unknown, and Snapshot
Reload / Collect all of the caches from Settings > Published Status
Complete system reboot
I feel like I am missing something fundamental and probably quite obvious... can anyone shed any light?
For info here is the value converter and some images of how it looks in Umbraco:
public class WeeklyScheduleValueConverter : IPropertyValueConverter
{
public bool IsConverter(IPublishedPropertyType propertyType)
=> Constants.WeeklySchedule.Alias == propertyType.EditorAlias;
public bool? IsValue(object value, PropertyValueLevel level)
{
return level switch
{
PropertyValueLevel.Source => value != null &&
(value is not string s || string.IsNullOrWhiteSpace(s) == false),
_ => throw new NotSupportedException($"Invalid level: {level}.")
};
}
public Type GetPropertyValueType(IPublishedPropertyType propertyType)
=> typeof(Models.WeeklySchedule);
public PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType propertyType)
=> PropertyCacheLevel.Elements;
public object ConvertSourceToIntermediate(IPublishedElement owner, IPublishedPropertyType propertyType, object source, bool preview)
{
var sourceString = source?.ToString();
if (string.IsNullOrWhiteSpace(sourceString))
{
return Models.WeeklySchedule.Empty;
}
return (JsonConvert.DeserializeObject<IEnumerable<WeeklyScheduleDayDto>>(sourceString) ??
Array.Empty<WeeklyScheduleDayDto>());
}
public object ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType,
PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
if (inter is not IEnumerable<WeeklyScheduleDayDto> schedule)
return null;
var enumeratedSchedule = schedule.ToList();
var weeklySchedule = Models.WeeklySchedule.Empty;
for (var i = 0; i < 7; i++)
{
var dayOfWeek = (DayOfWeek)i;
var dailySchedule = enumeratedSchedule.ElementAt(i).Value;
weeklySchedule[dayOfWeek].Enabled = dailySchedule.Enabled;
var parsedEntries = dailySchedule.Items.Select(item => new WeeklyScheduleDayItem { Start = item.Value?.Start, End = item.Value?.End }).ToList();
weeklySchedule[dayOfWeek].Items = parsedEntries;
}
return weeklySchedule;
}
public object ConvertIntermediateToXPath(IPublishedElement owner, IPublishedPropertyType propertyType,
PropertyCacheLevel referenceCacheLevel, object inter, bool preview)
{
return inter?.ToString();
}
}
I would expect the value for the 2 hour ticket to have two elements in for Sunday, like this:
But it's actually returning the results of the 3 hour ticket, like this:
As always guys any help is creatlly appreaciated, I think I'm going a little bit crazy.
Strange caching behaviour for custom property editor
Hi guys,
I have a custom property editor that is being used to specify the days and times certain activities take place on.
When I iterate over the schedules for the first time they have the correct values, but on subsequent requests every element has the same value - the last item according to 'Sort Order' in Umbraco.
It's as if the values are being cached somewhere / somehow using the same key, but I cannot for the life of me figure out what is going on.
I have tried the following to no avail:
PropertyCacheLevel
on the ValueConverter, triedNone
,Element
,Elements
,Unknown
, andSnapshot
I feel like I am missing something fundamental and probably quite obvious... can anyone shed any light?
For info here is the value converter and some images of how it looks in Umbraco:
I would expect the value for the 2 hour ticket to have two elements in for Sunday, like this:
But it's actually returning the results of the 3 hour ticket, like this:
As always guys any help is creatlly appreaciated, I think I'm going a little bit crazy.
TIA
Phil
Ok so it turns out I was being a sausage, as usual...
I was passing a static value instead of creating a new value in my model...
Should have been...
Is it the weekend yet?
is working on a reply...