You can cache a data object in a Microsoft Visual Studio 2005 Tools for the Microsoft Office System solution by adding the CachedAttribute attribute to an instance of a data type that meets certain requirements. Many common data types in the .NET Framework meet these requirements, including String, DataSet and DataTable. If you want to cache instances of data types that you create, the data types must meet these requirements.
Requirements for Data Objects to be Cached
To be cacheable, a data object must:
-
Be a read/write public field or property, not read-only or write-only.
-
Not be an indexer or other parameterized property.
In addition, the data object must meet the requirements of XmlSerializer. The data object must:
-
Be a public type.
-
Have a public constructor with no parameters.
-
Not execute code that requires additional security privileges.
-
Expose only read/write public properties (other properties will be ignored).
-
Not expose multi-dimensional arrays (nested arrays are accepted).
-
Not return interfaces from properties and fields.
-
Not implement IDictionary if a collection.
Any data item that has a null value is not cached. When you create a variable to hold a data object, you must initialize the value of the variable or it is not cached.
Option for Greater Control
You have the option of implementing ICachedType in your data object to give greater control over caching behavior. For example, you can implement this interface if you want to control how the user is notified when the object has been changed.
See Also