views:

61

answers:

2

I'm looking for a way to configure caching only for anonymous users only. The reason I'm looking to do this is when users are logged in and they create content they don't immediately see the content. In our old system (linux/php/mysql) we had it configured to cache only the anonymous users and this wasn't an issue.

Right now we have caching setup in the web.config like this

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      <add name="High" duration="60" varyByParam="*" enabled="true"/>
      <add name="Medium" duration="30" varyByParam="*" enabled="true"/>
      <add name="Low" duration="10" varyByParam="*" enabled="true"/>
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

I know that I can add a varyByCustom="userName" like this post is talking about. But this doesn't solve my problem. It still caches the users login and the same problem exists.

A: 

You can remove/expire the page from cache when a user makes changes to it using the method shown below:

HttpResponse.RemoveOutputCacheItem("/PageJustUpdated.aspx");
James Lawruk
+1  A: 

As James says it's probably better to invalidate the cache in some way.

That way your are maintaining a cache for all your users anonymous or not. Why not also improve responsiveness for your administrators, they are after all going to be using the application the most perhaps?

Have you looked at SQL cache dependancy? That way when the table that stores the content is altered then the cache is invalidated for you.

http://msdn.microsoft.com/en-us/library/system.web.caching.sqlcachedependency.aspx

Iain M Norman