Caching an ASP.NET HTTP Handler Server and Client Side Response

Is it possible to cache the response of the HTTP handler on the server and on the client?

This is not like a trick:

_context.Response.Cache.SetCacheability (HttpCacheability.Public); _context.Response.Cache.SetExpires (DateTime.Now.AddDays (7));

_context is an HTTPContext passed as an argument to the ProcessRequest method in the IHttpHandler implementation.

Any ideas?

Update: the client caches images uploaded via httphandler, but if the other client makes the same call, the server is not cached. Therefore, for each client that requests an image, the server goes to the database (and filestream). If we use the aspx page instead of the httphandler along with the caching profile, then the images will be cached both on the client and on the server.

+5
source share
2 answers

Thanks for your reply in the comments.

Cache.SetCacheability is used to determine if the proxy or client is allowed to cache, not on the server.

See IIS 7 for an explanation of how to cache HTTP handler output on a server.

+3
source

With IIS7, this can be done in web.config.

For example, suppose your url is ashx:

/ashxfiles/myhandler.ashx

... and you want to change the querystring parameters:

id lang

Add the following to your web.config:

<location path="ashxfiles">
    <system.webServer>
        <caching>
            <profiles>
                <add extension=".ashx" policy="CacheForTimePeriod" duration="00:00:10" varyByQueryString="id, lang" />
            </profiles>
        </caching>
    </system.webServer>
</location>

.ashx , .ashx , .

+4

All Articles