WCF-RIA Services OutputCache Client - How to Force a Cache Update

As mentioned in another question , we use WCF-RIA Services in our project in combination with the silverlight navigation map. There is a search function on the part. The search button will go to a special search page, placing the search request in the URL, which then initiates the RIA request on the server.

For this request, we have included the client output cache using this attribute:

[OutputCache(OutputCacheLocation.Client, duration: 2 * 60)] 

Now, sometimes (especially in the demo), our users know that the underlying data source has changed and they want to update the search to see the current results.

Installing LoadOperations LoadBehavior did not update the cache.

Now we have a (partial) solution: we have added a special cache counter property to our service. This property is ignored by the service and is used only for working with the cache. Whenever the user clicks the search button, the cache counter increases, and we work around the cache. If the user is moved back or redirected to the search page, the search counter is retrieved from Url and the request is served by the cache.

The question arises: is there a better way to force update the client’s cache?

Optional: our workaround is not suitable if the user selects the browser 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 did not find a way to detect the update from our silverlight client (I saw one sentence using a server-side session variable, which is not an option, because our server is completely stateless).

+6
source share
1 answer

We had the same problem, so instead we declared a common parameter in all Get methods called versions, and the version was a random number selected when the silverlight application started. When the refresh button is clicked, the version changes and updates the cache. When the user clicks the update button in the browser, silverlight will be restarted and a new random version will be selected. And for each next next / previous version, the variable will remain the same.

Example:

 public IQueryable<Products> GetProducts( string name, // ignore following int version ) { Return .... } 

Basically, a different version number identifies a different URL, so the browser or client-client ignores the cache and updates the results.

+4
source

Source: https://habr.com/ru/post/895240/


All Articles