As mentioned in another question we are using WCF-RIA Services in our project in combination with the silverlight navigation framework. On part is a search function. A search button will navigate to a special search page, putting the search query in the url, which will then trigger a RIA request on the server.
For this request we have enabled the Client output cache using this attribute:
[OutputCache(OutputCacheLocation.Client, duration: 2 * 60)]
Now, sometimes (especially in a demo) our users know, that the underlying datasource has changed and they want to refresh the search to see the current results.
Setting the LoadOperations LoadBehavior didn't refresh the cache.
For now we have a (partial) solution: we added a special cache counter property to our service. This property is ignored by the service and is only used to work around the cache. Whenever the user clicks on the search button, the cache counter is increased and we work around the cache. If the user navigates back or forward to the search page, the search counter is retrieved from the Url and the request is served by the cache.
The question is now: is there a better way to force a refresh of the client cache?
Additionally: our workaround fails short if the user chooses the browsers refresh button to refresh the search page. In this case the cache counter is still taken from the url and the data is retrieved from the cache instead of the server. I have found no way to detect a refresh from our silverlight client (I have seen one suggestion using a server-side session variable, which is not an option, because our server is completely stateless).
We had exact same problem so instead, we declared a common parameter in all 'Get' methods called version and version is a random number chosen in starting of silverlight app. When refresh button is clicked, version is changed and it refreshes the cache. When user clicks refresh button on browser, as silverlight will be restarted and a new random version will be chosen. And for every subsequent next/previous version variable will remain same.
Sample:
public IQueryable<Products> GetProducts(
string name,
// ignore following
int version )
{
Return ....
}
Basically different version number identifies a different URL so browser or http client ignores cache and refreshes the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With