C# - How To Implement Caching Of Static Files

Mar 15, 2011

I use a Masterpage (asp.net webforms) on my site and I woluld like to implement caching of some static files, like javascript, css etc.

I've tried adding the following to my page_load (in the masterpage) but when I use Fiddler the static files are still under "no-cache".

protected void Page_Load(object sender, EventArgs e)
{
// Set cache for 1 hour on all computers and servers.
// ... Proxies, browsers, and your server will cache it.
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetMaxAge(new TimeSpan(1, 0, 0));
}

What am i doing wrong here?

View 1 Replies


Similar Messages:

WCF / ASMX :: Implement Caching Using System.Web.Caching?

May 15, 2010

how to implement caching in wcf service using System.Web.Caching

View 2 Replies

Output Caching On Static Pages?

Jan 28, 2010

Does output caching help boost the performance of asp.net mvc pages that just consist of html, css, images, and javascript?

View 1 Replies

C# - Caching Through HttpContext.Current.Cache Or Just A Static?

Mar 28, 2011

Last night I wrote up my first IHttpModule to do some request processing. I'm using a regular expression to inspect the raw url. The IHttpModule will be called on every request, so it seems reasonable to do some sort of caching of the regular expression object to prevent creation of it on every request.

Now my question... what is better: use the HttpContext.Current.Cache to store the instantiated object or to use a private static Regex in my module?I'm looking forward to the reasons why. Just to clarify: the regex will never change and thus always be the same thing.

View 3 Replies

State Management :: Caching With Static Classes?

Jul 3, 2010

Currently I have my data cached in Datasets in a static class. I was talking to my cousin's husband, who works as a C# developer for our local Telecom company.

Basically, I'm pretty new to ASP.NET and although to me having cached data in a static class makes sense to me, when I talked to him about it, he said there might be a problem when the site goes live, as on a web server more than one instance of the class may be created.

He did say this was a theory, and it was an area he didn't know an awful lot about, so I thought I'd ask some of you ASP.NET gurus to see if what I've done is totally wrong or not.

View 12 Replies

C# - Caching W/file Dependency: Static Var Vs. AspNet Cache Vs. Memcached

Sep 29, 2010

TL;DR: Which is likely faster: accessing static local variable, accessing variable stored in HttpRuntime.Cache, or accessing variable stored in memcached?At work, we get about 200,000 page views/day. On our homepage, we display a promotion. This promotion is different for different users, based on their country of origin and language.

All the different promotions are defined in an XML file on each web server. We have 12 web servers all serving the same site with the same XML file. There are about 50 different promotion combinations based on country/language. We imagine we'll never have more than 200 or so (if ever) promotions (combinations) total.

The XML file may be changed at any time, out of release cycle. When it's changed, the new definitions of promotions should immediately change on the live site. Implementing the functionality for this requirement is the responsibility of another developer and I.

Originally, I wrote the code so that the contents of the XML file were parsed and then stored in a static member of a class. A FileSystemWatcher monitored changes to the file, and whenever the file was changed, the XML would be reloaded/reparsed and the static member would be updated with the new contents. Seemed like a solid, simple solution to keeping the in-memory dictionary of promotions current with the XML file. (Each server doing this indepedently with its local copy of the XML file; all XML files are the same and change at the same time.)

The other developer I was working holds a Sr. position and decided that this was no good. Instead, we should store all the promotions in each server's HttpContext.Current.Cache with a CacheDependency file dependency that automatically monitored file changes, expunging the cached promotions when the file changed. While I liked that we no longer had to use a FileSystemWatcher, I worried a little that grabbing the promotions from the volitile cache instead of a static class member would be less performant.

(Care to comment on this concern? I already gave up trying to advocate not switching to HttpRuntime.Cache.)

Later, after we began using HttpRuntime.Cache, we adopted memcached with Enyim as our .NET interface for other business problems (e.g. search results). When we did that, this Sr. Developer decided we should be using memcached instead of the HttpRuntime (HttpContext) Cache for storing promotions. Higher-ups said "yeah, sounds good", and gave him a dedicated server with memcached just for these promotions. Now he's currently implementing the changes to use memcached instead.

I'm skeptical that this is a good decision. Instead of staying in-process and grabbing this promotion data from the HttpRuntime.Cache, we're now opening a socket to a network memcached server and transmitting its value to our web server.This has to be less performant, right? Even if the cache is memcached. (I haven't had the chance to compile any performance metrics yet.)On top of that, he's going to have to engineer his own file dependency solution over memcached since it doesn't provide such a facility.

Wouldn't my original design be best? Does this strike you as overengineering? Is HttpRuntime.Cache caching or memcached caching even necessary?

View 2 Replies

Caching In .net - Error Like "An Object Reference Is Required For Non Static Field?

Feb 9, 2011

I m having a webService.

In that I m using Caching.

I have wrote following code to store datatable in cache.

using System.Web.Caching;

Cache.Insert("dt", dt, null, DateTime.Now.AddHours(1), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Default, null);


It give me error like "An object Reference is required for non static field.

View 2 Replies

Can Implement Caching In MVC, If So How

Apr 4, 2011

Can I Implement Caching in MVC, If so how? I wanted to implement Cache in Controllers

View 2 Replies

C# - How To Implement SQLDependency Caching

Sep 29, 2010

explain me how to implement SQL Dependency Caching in Asp.Net?

View 3 Replies

C# - How To Implement VaryByCustom Caching

Mar 15, 2011

I'm trying to implement functionality to cache certain pages depending on the host. This is because I can have multiple versions of a page which have the same parameters, and where the only difference in terms of a request is the host that is being requested. So, for example these two URLs will request the same page, but they are styled differently:[URL]and [URL]


I'm going through the example outlined here:[URL]but it's not making sense to me.

I've added this to my global.asax:

public override string GetVaryByCustomString(HttpContext context, string arg)
{
if (arg == "host")
{
return "host=" + context.Request.Url.Host;
}
return base.GetVaryByCustomString(context, arg);
}

and the example states "To set the custom string programmatically, call the SetVaryByCustom method and pass it the custom string to use", with code similar to the following:

Response.Cache.SetVaryByCustom("host");

The problem is I'm not sure what to do with this. I've added the previous line to MvcApplication_EndRequest because it seems like it makes sense, but I don't think this is right because when I set breakpoints in GetVaryByCustomString they never get hit.

[Code]....

View 4 Replies

C# - How To Implement Caching For The Whole Page Except User Control

Sep 25, 2010

I have aspx page with a user control. I want to implement caching for the entire page except the user control.

View 2 Replies

MVC :: How To Implement Page Caching On A Social Networking Web App

Jul 14, 2010

i am in the process of developing a social networking web app using asp.net mvc 2 and asp.net 3.5 sp1.I have implemented user authentication and role management (like admins, etc...) and i was wondering how i could implement page caching in such a scenario based on the user currently logged in.

Note that the web app page urls may, or may not contain the name of the user authenticated and that there are also pages available to both authenticated and both authenticated users.

What i would like to avoid is to make a cache version of a page for an authenticated user, available to a non authenticated or to another authenticated user.

View 3 Replies

State Management :: How To Implement Caching To A Dropdown List

Dec 3, 2010

How to implement caching to a dropdown list

View 2 Replies

How To Implement Cascading Static Dropdownlist

Jul 6, 2010

implementing cascading static dropdownlist in asp.net

View 1 Replies

Web Forms :: How To Implement Partial Page Caching With An AdRotator Control

Aug 18, 2010

How do I implement partial page caching with an AdRotator control? I know it's supposed to do it automatically, but I'm using the AdCreated event to handle stats, and this seems to cause the ad to be cached along with the rest of the page.

View 4 Replies

Caching Css And .js Files?

Dec 5, 2010

I want to use caching technique for .js,.css and images( to avoid round trips and to improve performance of page load) .So, on IIS 7 using Http Response Header, i set Content Expriation to 7 days.Now, on browser its caching which is avoiding round trips for static content ...which is good sign.Now, i modified one of the .js file and i deployed that .js file on server and due to caching my new code is not reflecting on client machines .So i tried lot of ways and here is what i tried after deployment of new .js file After deployment of new .js file

1) I manually delete all the browser cache(cookies,urls,forms,page content etc) on internet explorer

2) used ctrl + f5 to get refresh

3) again on IIS i went back Http Response Header section and set Content Expriation to never

4) stopped the website and restarted

5) on web.config file tried this only

<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>

6) Also tried to set this on .aspx page

<HTML>
<HEAD>
<TITLE>---</TITLE>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD>
<BODY>

7) tried to set this on .aspx.cs file

<% Response.CacheControl = "no-cache" %>>
<% Response.AddHeader "Pragma", "no-cache" %>
<% Response.Expires = -1 %>

My target browser is IE.None of them worked,Finally i renamed my .js file to different file name and changed code to make use of that new .js file ..but no luck on this too .Because what i set intially for 7 days still my client machine remembers that.

How do i tell IIS server to refresh cached content code , when some thing got changde on .js or .cssfiles?

View 1 Replies

Caching - How To Turn Pages Into Static Pages As Part Of The Build

Dec 29, 2010

I have a few pages that are completely static. They only change at build time. But they are expensive to create. For the ones that are kind of expensive to create, I cache them for very long times using the ASP.NET output caching. But for one page, I really want it cached forever and ever or until the the next build.

What is the most expedient way to make this happen? Is there a build in feature that achieves this or a 3rd party tool?

(yeah, for the moment I plan to do the "view source" and copy paste thing, which isn't a very elegant build step)

View 2 Replies

Web Forms :: Caching Images / Files Without Using Iis?

Feb 1, 2011

i recently made a website and have uploaded it to a hosting server. After i had completed the website i noticed that i never added in any expiration onto the files/images plus that i dont know how to do this outside of IIS. As i dont have access to the IIS on the server i need a way of embeding code to set a short exportaion on the images and xml files cached. whats the best way of doing this?

View 5 Replies

Configuration :: Caching And GZIPing Javascript Files?

Apr 26, 2010

i have some javascripts file which i need those to be chached for my website. also can i GZIP javascript files?

View 2 Replies

Web Forms :: Clearing Browser Caching Xml Files?

Nov 30, 2010

i want ot clear the browser caching xml files as i am not abel to load the newly edited xml file

View 4 Replies

Refresh # Include Files - Caching On IIS7 / ASP?

Jul 28, 2010

I have an ASP.NET master page which references a #include file as follows:

<!--#include virtual="/includes/scripts.inc"-->

I have modified the file /includes/scripts.inc but the changes do not show up in pages. What needs to be done so modifications will be reflected? I need to avoid the following: restarting the server restarting IIS modifying web.config (doesn't appear to have any effect)
pretty much anything that causes the app domain to restart Any other options? Is there a setting which affects how long IIS caches #include files?

View 4 Replies

Mvc Site Is Not Caching Content Or Script Files?

Mar 18, 2010

My asp mvc site is not caching content or script files. How do I get it to cache such?

View 1 Replies

Web Forms :: Caching Of Files - Noticeable Delay As Asp Recompiles

Mar 15, 2011

I have gotten confused about how page caching works in ASP.NET. Suppose a user has navigated to "home.aspx" on my website and say I release a new version of that page to the server and the user subsequently navigates to that page, he will get the updated version, is that correct? Is there ever a case where I need to be concerned that the user is NOT getting the latest version of a page(or code-behind) file? The reason I am confused is that quite sometime ago, I found the following code to put in my Page_load event to prevent page caching:

[Code]....

But the more I think about it, I cannot remember the rationale behind this. Whenever I do a release and subsequently visit my site, there is a noticable delay as ASP recompiles. So now I am wondering why the above "no caching" code would be needed or when it is appropriate to use.

View 1 Replies

Caching - ASPX And ASCX Files Not Updating When Saved?

Mar 4, 2011

At some point in the last month, two web application projects that I've been working on have stopped showing updates to aspx and ascx files until IIS is restarted, or the website they belong to is reset. This seems to be very random and I can't find any reason in the web.config sections that would cause this change. What are some good places to look for a source to this issue?Current caching parts of web.config: Removing the outputCacheProfile and restarting IIS made no difference.

<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="ClientResourceCache" location="None" enabled="true" duration="3600" varyByParam="*" varyByContentEncoding="gzip;deflate"/>
</outputCacheProfiles>
</outputCacheSettings>
</caching>

Commening out the staticConent and restarting also made no difference

<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00">
</clientCache>
</staticContent>
<caching>
<profiles>
<add extension=".gif" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".png" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".js" policy="DontCache" kernelCachePolicy="DontCache" duration="00:01:00" location="Any" />
<add extension=".css" policy="DontCache" kernelCachePolicy="DontCache" duration="00:01:00" location="Any" />
<add extension=".jpg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
<add extension=".jpeg" policy="DontCache" kernelCachePolicy="CacheUntilChange" duration="0.00:01:00" location="Any" />
</profiles>
</caching>

We've also tried adding .ascx and .aspx extensions with CacheUntilChange which made no difference. Other sites with these same settings aren't having the issue. Edit: Originally this state that there also was no update when the project was built, I haven't personally been able to confirm that issue but was told by another developer that was occurring.

View 2 Replies

Necessary To Manually Cache Static Files In C#?

Nov 29, 2010

I have a class that is creating an instance of StreamReader to an xml file on the local filesystem.
It may be possible that this same file is requested multiple times per-second.

I was wondering whether I need to manually add this file to the System.Web.Cache and read it from there, or whether Windows itself is clever enough to cache the item itself so that it 'knows' when ASP.NET requests this file the second/third etc time that it doesnt have to do a disk seek/read operation and pulls it from its own cache?

This article: http://dotnetperls.com/file-read-benchmarks seems to back this up, but this: article:

[URL](although not discussing from a performance perspective, and maybe for other reasons entirely) lists how to add a physical file to the cache.

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved