none
Trying to understand CacheMetadata

    Question

  • Hello,

    I am trying to understand the concept of CacheMetadata method..

    According to my research, it looks like this needs to be overridden for performance reason or validation.

    I don't think those are only reasons.

    There are many methods available from NativeActivityMetadata argument.

    What exactly does this method do?

    I meant, if I don't consider the performance/or validation, no need to override this method?

    I am not sure this would be good example though.

    For example, http://xhinker.com/post/WF4My-Composite-Activity.aspx, in this article, what makes difference between

    overridden CacheMetadata method or not?

    It looks like this article code works OK without even overriding the CacheMetaData method..

    Would like to understand this method exactly.

    Thanks,

    Thursday, March 01, 2012 6:23 PM

Answers

  • Hi,

    According to the document, "The default implementation of this method provides the runtime with all of the public arguments, variables, and child activities exposed by the activity at the time it is executed; if the activity needs to give more information to the runtime than this (such as private members, or activities to be scheduled by the activity), this method can be overridden to provide it."  As the branches and variables are public, hence the article code works OK without overriding the CacheMetaData method.

    Exposing data with CacheMetadata

    http://msdn.microsoft.com/en-us/library/gg427636.aspx

    Tim's blog entry is very helpful for us understanding the CacheMetadata method.

    Misadventures in CacheMetadata – wrapping an inner activity, in code

    http://blogs.msdn.com/b/tilovell/archive/2010/02/26/misadventures-in-cachemetadata-wrapping-an-inner-activity-in-code.aspx

    In addition, you might browse System.Activities assembly, check the implementation of this method by using IL Spy or Reflector.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 06, 2012 8:01 AM
    Moderator
  • When creating a simple activity you typically do not need to override CacheMetadata.  However, many activity authors do override it because the base implementation uses reflection to determine the public properties.  As the activity author you can provide these values in CacheMetdata avoiding reflection to get better performance.

    For more advanced scenarios you will have to override CacheMetadata to deal with things like implementation variables/children and others.


    Sr. Program Manager, Windows Azure Platform Team(WF) http://blogs.msdn.com/rjacobs http://www.twitter.com/ronljacobs

    Thursday, March 08, 2012 5:13 PM

All replies

  • Hi,

    According to the document, "The default implementation of this method provides the runtime with all of the public arguments, variables, and child activities exposed by the activity at the time it is executed; if the activity needs to give more information to the runtime than this (such as private members, or activities to be scheduled by the activity), this method can be overridden to provide it."  As the branches and variables are public, hence the article code works OK without overriding the CacheMetaData method.

    Exposing data with CacheMetadata

    http://msdn.microsoft.com/en-us/library/gg427636.aspx

    Tim's blog entry is very helpful for us understanding the CacheMetadata method.

    Misadventures in CacheMetadata – wrapping an inner activity, in code

    http://blogs.msdn.com/b/tilovell/archive/2010/02/26/misadventures-in-cachemetadata-wrapping-an-inner-activity-in-code.aspx

    In addition, you might browse System.Activities assembly, check the implementation of this method by using IL Spy or Reflector.


    Leo Tang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 06, 2012 8:01 AM
    Moderator
  • When creating a simple activity you typically do not need to override CacheMetadata.  However, many activity authors do override it because the base implementation uses reflection to determine the public properties.  As the activity author you can provide these values in CacheMetdata avoiding reflection to get better performance.

    For more advanced scenarios you will have to override CacheMetadata to deal with things like implementation variables/children and others.


    Sr. Program Manager, Windows Azure Platform Team(WF) http://blogs.msdn.com/rjacobs http://www.twitter.com/ronljacobs

    Thursday, March 08, 2012 5:13 PM