Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure ASP.NET caching for anonymous only?

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.

like image 597
Nathan Palmer Avatar asked Nov 14 '22 12:11

Nathan Palmer


1 Answers

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

like image 119
Iain M Norman Avatar answered Dec 22 '22 11:12

Iain M Norman