I'm using the following code to open a connection to a feature server and adding a feature layer to the current map:
<SPAN class="keyword token">var</SPAN> serviceUrl <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>@"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Furl-of-feature-server%2FFeatureServer" target="_blank">http://url-of-feature-server/FeatureServer</A><SPAN>"</SPAN></SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> layerId <SPAN class="operator token">=</SPAN> <SPAN class="string token">"0"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> map <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">.</SPAN>Map<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> geoDb <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Geodatabase</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ServiceConnectionProperties</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Uri</SPAN><SPAN class="punctuation token">(</SPAN>serviceUrl<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> defNames <SPAN class="operator token">=</SPAN> geoDb<SPAN class="punctuation token">.</SPAN>GetDefinitions<SPAN class="operator token"><</SPAN>FeatureClassDefinition<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Select</SPAN><SPAN class="punctuation token">(</SPAN>def <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> def<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetName</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToArray</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> id <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Parse</SPAN><SPAN class="punctuation token">(</SPAN>layerId<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Debug<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Assert</SPAN><SPAN class="punctuation token">(</SPAN>defNames<SPAN class="punctuation token">.</SPAN>Length <SPAN class="operator token">></SPAN> id<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>defNames<SPAN class="punctuation token">.</SPAN>Length <SPAN class="operator token">></SPAN> id<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> featureClass <SPAN class="operator token">=</SPAN> geoDb<SPAN class="punctuation token">.</SPAN>OpenDataset<SPAN class="operator token"><</SPAN>FeatureClass<SPAN class="operator token">></SPAN><SPAN class="punctuation token">(</SPAN>defNames<SPAN class="punctuation token">[</SPAN>id<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
featureLayer <SPAN class="operator token">=</SPAN> LayerFactory<SPAN class="punctuation token">.</SPAN>Instance<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateFeatureLayer</SPAN><SPAN class="punctuation token">(</SPAN>featureClass<SPAN class="punctuation token">,</SPAN> map<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
featureLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetDisplayCacheType</SPAN><SPAN class="punctuation token">(</SPAN>DisplayCacheType<SPAN class="punctuation token">.</SPAN>None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
featureLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">SetDisplayCacheMaxAge</SPAN><SPAN class="punctuation token">(</SPAN>TimeSpan<SPAN class="punctuation token">.</SPAN>Zero<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>This works fine the 1st time this code gets executed. If the feature server has N feature layers then defNames gets N definitions.
If the feature server gains a new layer, one would expect that the next time this code gets executed defNames would have N + 1 items. However it still returns N definitions. Using Fiddler, I can see that ArcGIS performs HTTP requests (to get feature definitions, metadata, etc.) the 1st time the Geodatabase object is created. Subsequent creations of new Geodatabase objects (using the same service URL) does not make any other HTTP requests, even when geoDb object was disposed via "using", as if it was being cached by ArcGIS.
I would like to ensure that every time I create a new Geodatabase object that it has the most recent feature definitions and ArcGIS doesn't cache anything. How would one do that?
Additionally, I've noticed that SetDisplayCacheType(DisplayCacheType.None) does not seem to apply or update the layer's properties (checking via Layer->Properties->Cache).