开发者

Advice to implement cache solution for a site

I'm working on a public site that soon will not 开发者_JAVA百科longer be 100% public. Paid users will be able to access 100% of the features while "anonymous" users will access a reduced version.

The problem is that anonymous users and paid users will access the same pages, but they'll see different things.

I wonder about how to keep using cache for all pages. I have to 100% sure that I show the correct content for each type of user. Will be extremely bad to show a cached version of the paid site to an anonymous user (and the other way around).

Preferably, without adding anything to the url to differentiate user type.

Thanks!


You can use the application cache for your business data, which is basically a dictionary of key value pairs, which you can put anything you like into. Then you can programatically check if they're logged in. You'll still be rendering the page on each visit, but hopefully retrieving the cached data will provide the required performance boost.

Alternatively, it might be possible to turn off the output-cache programatically, as described in this question.

Quote this answer from David Ebbo:

In OnInit:

if (yourArbitraryCondition) {
    OutputCacheParameters outputCacheSettings = new OutputCacheParameters();
    outputCacheSettings.Duration = 60;
    InitOutputCache(outputCacheSettings);
}


I think what you are looking for would be accomplished by the varybycustom option for output caching. Using this you define a function to return a custom parameter value that is used when retrieving the output cached version of a page so that users will get their own personalized cached version, and all anonymous users should see the same cached version since they will be using some the same value. Here is a link with more information: http://aspadvice.com/blogs/ssmith/archive/2007/10/29/VaryByCustom-Caching-By-User.aspx

For programmatic data caching you should use the user id as part of they key to retrieve the data to achieve the same effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜