1

I know that i can use the VaryByParam attribute, but what it does is not exactly what i am aiming for.

What happens is that different versions of the page are cached based on the query string.

For example Page.aspx?ID=Tom has its own cached version and ID=Arnold has another. Now what i want to do is not to cache Arnold at all. I only want to cache the page when the query string is Tom.

Any ideas?

3 Answers 3

1

For C#

    public static void cacheOutput(Page page, double minutes)
    {
        page.Response.Cache.SetExpires(DateTime.Now.AddMinutes(minutes));
        page.Response.Cache.SetCacheability(HttpCacheability.Server);
        page.Response.Cache.SetValidUntilExpires(true);
    }

It's better to take a double for minutes. Good solution! Thx!

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use VaryByCustom and override GetVaryByCustomString method in the Application class.

Comments

0
    <Extension()> _
    Public Sub CacheOutput(ByVal Page As Page, ByVal Minutes As Integer)
        Page.Response.Cache.SetExpires(Date.Now.AddMinutes(Minutes))
        Page.Response.Cache.SetCacheability(HttpCacheability.Server)
        Page.Response.Cache.SetValidUntilExpires(True)
    End Sub

This works. Note that any version of the page that has a querystring or a POST parameter will not be cached.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.