Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to invalidate items cached using an OutputCacheProvider in WCF Data Service?
    primarykey
    data
    text
    <p>I have an implementation of data caching in a wcf data service that follows this; <a href="http://blogs.msdn.com/b/peter_qian/archive/2010/11/17/using-asp-net-output-caching-with-wcf-data-services.aspx" rel="nofollow">http://blogs.msdn.com/b/peter_qian/archive/2010/11/17/using-asp-net-output-caching-with-wcf-data-services.aspx</a></p> <p>Toward the end of the article it suggets that you can implement your own custom cache provider by extending OutputCacheProvider. I have done this and tested the cache works fine.</p> <p>I cannot however, get the output cache to work with a data cache dependency as outlined in the above article. As soon as a add in the line;</p> <pre><code> context.Response.AddCacheItemDependency(cacheDependencyItemKey); </code></pre> <p>I get the following error;</p> <p>*When using a custom output cache provider like 'DiskOutputCache', only the following expiration policies and cache features are supported: file dependencies, absolute expirations, static validation callbacks and static substitution callbacks. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p> <p>Exception Details: System.Configuration.Provider.ProviderException: When using a custom output cache provider like 'DiskOutputCache', only the following expiration policies and cache features are supported: file dependencies, absolute expirations, static validation callbacks and static substitution callbacks.</p> <p>Source Error: </p> <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</p> <p>Stack Trace: </p> <p>[ProviderException: When using a custom output cache provider like 'DiskOutputCache', only the following expiration policies and cache features are supported: file dependencies, absolute expirations, static validation callbacks and static substitution callbacks.] System.Web.Caching.OutputCache.InsertResponse(String cachedVaryKey, CachedVary cachedVary, String rawResponseKey, CachedRawResponse rawResponse, CacheDependency dependencies, DateTime absExp, TimeSpan slidingExp) +2905959 System.Web.Caching.OutputCacheModule.OnLeave(Object source, EventArgs eventArgs) +107 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +75***</p> <pre><code> protected override void OnStartProcessingRequest(ProcessRequestArgs args) { base.OnStartProcessingRequest(args); HttpContext context = HttpContext.Current; if (context.Cache.Get(cacheDependencyItemKey) == null) { // what the cache item value is doesn't really matter context.Cache.Insert(cacheDependencyItemKey, "Item"); } if (context.Request.HttpMethod.Equals("POST", StringComparison.OrdinalIgnoreCase) || context.Request.HttpMethod.Equals("MERGE", StringComparison.OrdinalIgnoreCase) || context.Request.HttpMethod.Equals("PUT", StringComparison.OrdinalIgnoreCase) || context.Request.HttpMethod.Equals("DELETE", StringComparison.OrdinalIgnoreCase)) { context.Cache.Remove(cacheDependencyItemKey); } else { // set cache policy to this page HttpCachePolicy cachePolicy = context.Response.Cache; // server&amp;private: server and client side cache only cachePolicy.SetCacheability(HttpCacheability.ServerAndPrivate); // default cache expire: never cachePolicy.SetExpires(DateTime.MaxValue); // cached output depends on: accept, charset, encoding, and all parameters (like $filter, etc) cachePolicy.VaryByHeaders["Accept"] = true; cachePolicy.VaryByHeaders["Accept-Charset"] = true; cachePolicy.VaryByHeaders["Accept-Encoding"] = true; cachePolicy.VaryByParams["*"] = true; cachePolicy.SetValidUntilExpires(true); // add data cache dependency context.Response.AddCacheItemDependency(cacheDependencyItemKey); } } </code></pre> <p>This error would seems to suggest that you cannot use a CacheItemDependency in WCF like this. I'm confused as it appears to work in the msdn blog article.</p> <p>Any thoughts?</p> <p><strong>Batch updates appear to be problematic</strong></p> <p>In data services when you are using the <em>DataServiceContext</em> and excute <em>SaveChanges(SaveChangesOptions.Batch);</em> the request uri looks like "~/$batch" so there doesn't appear to be an easy way to actually determine what is being created, updated or deleted in attempt to invalidate those items.</p> <p>I am assuming in the logic block below for changes to the web service data you would have to call a remove directly on the cache, and have the underyling cache provider work out what needs to be removed. But there doesn't seem to be an easy way to actually determine what has changed. Am I missing something here?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload