Skip to content

Commit 61c83ef

Browse files
authored
Update wv2winrt-cacheable-properties.md
1 parent 5ed69b6 commit 61c83ef

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

specs/wv2winrt-cacheable-properties.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ performance.
2525
Boolean Available { get; };
2626

2727
// This property has one value for the lifetime of the object so we mark it
28-
// readonly to improve wv2winrt performance.
29-
[corewebview2readonly]
28+
// memoizable to improve runtime performance.
29+
[memoizable]
3030
String Model { get; };
3131

3232
// ...
@@ -38,16 +38,34 @@ performance.
3838
```c# (but really MIDL3)
3939
namespace Microsoft.Web.WebView2.Core
4040
{
41-
/// You can use the CoreWebView2ReadOnly attribute on a runtimeclass property
42-
/// definition in MIDL3 if the property value doesn't change for the lifetime
43-
/// of its object. When an object is projected into JavaScript via
41+
/// You can use the `memoizable` attribute on a runtimeclass property
42+
/// or runtimeclass method to indicate that the property value or
43+
/// method return value can be cached.
44+
///
45+
/// You can apply it to an instance property if the property
46+
/// value doesn't change for the lifetime of its object instance.
47+
/// You can apply it to a static property if the property value
48+
/// doesn't change for the lifetime of the process.
49+
/// You can apply it to an instance method if when the method is called
50+
/// with the same parameters it always returns the same value for the
51+
/// lifetime of its object instance.
52+
/// You can apply it to a static method if when the method is called
53+
/// with the same parameters it always returns the same value for the
54+
/// lifetime of the process.
55+
/// If the property type or the method return type is an object, the property
56+
/// value must be the same object by reference or the method must return the
57+
/// same object by reference in order to be memoizable. Merely returning an
58+
/// equivalent but different object is not sufficient to be memoizable.
59+
/// Similarly, a method call having the same parameters means the same object
60+
/// references and not equivalent but different objects.
61+
///
62+
/// When an object is projected into JavaScript via
4463
/// `CoreWebView2.AddHostObjectToScript`, WebView2 will cache property values
4564
/// marked with this attribute. This can potentially improve performance by
46-
/// reducing the number of cross-process calls to obtain the latest value of
47-
/// the property.
48-
[attributeusage(target_property)]
49-
[attributename("corewebview2readonly")]
50-
attribute CoreWebView2ReadOnlyAttribute
65+
/// reducing the number of cross-process calls to obtain the latest value.
66+
[attributeusage(target_property, target_method)]
67+
[attributename("memoizable")]
68+
attribute MemoizableAttribute
5169
{
5270
}
5371
}
@@ -56,14 +74,14 @@ namespace Microsoft.Web.WebView2.Core
5674
# Appendix
5775

5876
Names considered for the attribute:
59-
* **Cacheable**: Caching is what WebView2 will do with the property rather than describing
60-
an aspect of the runtimeclass property.
77+
* **Cacheable**
6178
* **ReadOnly**: Similar to C#'s readonly keyword which indicates a value won't change (once
62-
initialized). A more familiar term to end developers than 'immutable'. It does
63-
convey that the caller can't set it, but does it also convey that the implementer also
64-
cannot change the value?
65-
* **Immutable**: Perhaps more explicit than readonly that the implementer also cannot
66-
change the value, but perhaps less familiar of a term.
79+
initialized). But does not convey that the implementer cannot change the value.
80+
* **Immutable**: Similar to readonly
81+
* **Const**: Does a better job indicating that the value does not change even by the
82+
implementer.
83+
* **Memoizable**: A broader term than cacheable that also applies to methods but more specific
84+
than cacheable in that it better defines the kind of caching.
6785

6886
For the sample code, the only code you have to write is applying the attribute to the
6987
property. The only effect this has is to potentially improve performance so there's no other

0 commit comments

Comments
 (0)