This project is read-only.

Cached Value

Sep 3, 2011 at 11:36 AM

Hi Throb,

I try to upgrade my project with the latest changeset of obtics.

In my old version, the first get of ".Value" and the second, take the same time... so there are not cache of the value.
In the latest, there are no changes about this =( I have try to import the "CachedTransformation" of WPF version in silverlight, but same with Cached() :(

Is there a ended transformation that keeps the value in cache and did not recompute the value for each access ?

Regs,
Vincent

 

Sep 16, 2011 at 12:21 AM

Hi Vincent,

Cached() should work though but it will work only when at least one client is registered for change notifications.

If it still does not work could you post some code that shows this problem?

Regs,

Thomas

Oct 7, 2011 at 3:36 PM

Hi Throb,

I am very disapppointed, I try this code :


EmployeesSchedulesViewModel employeesSchedulesViewModel = (this.LayoutRoot.DataContext as EmployeesSchedulesViewModel);
            var selectMany = employeesSchedulesViewModel.PlanningDomainContext.Employees
                .SelectMany(evm => evm.WorkDays).Take(10)
                .Select(wd => DynamicWorkDay.GetOrCreate(wd.Employee, wd.Date, wd.IsRealized)).ToList();


            List<string> colors = new List<string>();

            DateTime datetime = DateTime.Now;
            foreach (DynamicWorkDay workDay in selectMany)
            {
                ((INotifyPropertyChanged)workDay.Color).PropertyChanged += new PropertyChangedEventHandler(EmployeesSchedulesView_PropertyChanged);
                string valueProvider = workDay.Color.Value;
                colors.Add(valueProvider);
            }
            TimeSpan timeSpan = DateTime.Now - datetime ;
            datetime = DateTime.Now;
            foreach (DynamicWorkDay workDay in selectMany)
            {
                string valueProvider = workDay.Color.Value;
                colors.Add(valueProvider);
            }

            TimeSpan timeSpan2 = DateTime.Now - datetime;

            MessageBox.Show(selectMany.Count + " "+timeSpan.TotalMilliseconds + " " + timeSpan2.TotalMilliseconds);

 

  

When I don't suscribe to PropertyChanged of Color ValueProvider, the value of MessageBox is "10 4060.23 4058.23" then I suscribe, the result is "10 8.0 0", WTF ?

Regs,
Vincent

Oct 13, 2011 at 2:33 PM

Hi Vincent,

I don't know about the details of your project. In general it is not strange that Obtics would perform (much) beter when clients have registered for change notifications. I short; Obtics does not track changes when no clients are registered. This makes sense because you don't want Obtics to waste resources on transformation pipelines you don't need anymore. So when you ask for the value it will be recalculated every time. When clients ARE registered for change notifications Obtics will track them and (because you use ToList()) may cache the result. This means that the value result may not be recalculated every time you ask for it and the result is a better performance.

In case you don't want to register for change notifications (directly via INotifyPropertyChanged or ICollectionChanged or indirectly via bindings) I'd suggest you use plain LINQ and not Obtics.

Regs,

Thomas.

Oct 13, 2011 at 2:52 PM

Hi Throb,

Thanks for your answer. I have several problems about performance in my application who use Obtics (in very old version) =(

Vincent