locked
Outputcache VaryByCustom RRS feed

  • Question

  • User-1122939121 posted

    Is it possible to have the Varybycustom string supplied/created by the page in a Web Forms App?

    I have a page with a search filter and I want to create a string in the page like "Color:Red;Size:Lg" and have the cached item be created based on that parameter.

    All of the examples I've seen use an existing variable that already exists in HttpContext. Everything I have tried so far doesn't seem to work. A property on the page can be read but the timing is somehow wrong to create anything but the very first cache entry. I can read a cookie from the GetVaryByCustomString but when I set a cookie on the page I want to cache it seems to remove caching from the page,  GetVaryByCustomString never fires.

    I don't understand how Varybycustom would be very useful if you can't actually supply a custom string.  I can set a string by using Response.Cache.SetVaryByCustom(SomeOutputCacheKey); but that produces weird results. It seems to create unique cache entries the first couple of times but after a point all of the autopostback stuff seems to quit working. Using varybyparam="*" the first trip produces and entry for the page and an entry for webresource.axd file so I get a total of 4 cache entrys. The second trip will give me 8 cache entries but the third try will always just return the second entry.

    Is what I'm trying to do even possible?

    Tuesday, September 22, 2015 1:46 PM

All replies